Skip to content

Commit

Permalink
PSR and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed May 16, 2016
1 parent 9e1a243 commit 438f325
Show file tree
Hide file tree
Showing 34 changed files with 196 additions and 131 deletions.
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<phpunit bootstrap="./vendor/autoload.php"
colors="true"
convertNoticesToExceptions="false">

<testsuites>
<testsuite name="GoetasWebservices WSDL Reader Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
Expand Down
106 changes: 46 additions & 60 deletions src/DefinitionsReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@

use DOMDocument;
use DOMElement;
use GoetasWebservices\XML\WSDLReader\Events\Binding\FaultEvent as BindingOperationFaultEvent;
use GoetasWebservices\XML\WSDLReader\Events\Binding\MessageEvent as BindingOperationMessageEvent;
use GoetasWebservices\XML\WSDLReader\Events\Binding\OperationEvent as BindingOperationEvent;
use GoetasWebservices\XML\WSDLReader\Events\BindingEvent;
use GoetasWebservices\XML\WSDLReader\Events\DefinitionsEvent;
use GoetasWebservices\XML\WSDLReader\Events\Message\PartEvent as MessagePartEvent;
use GoetasWebservices\XML\WSDLReader\Events\MessageEvent;
use GoetasWebservices\XML\WSDLReader\Events\PortType\FaultEvent;
use GoetasWebservices\XML\WSDLReader\Events\PortType\OperationEvent;
use GoetasWebservices\XML\WSDLReader\Events\PortType\ParamEvent;
use GoetasWebservices\XML\WSDLReader\Events\PortTypeEvent;
use GoetasWebservices\XML\WSDLReader\Events\Service\PortEvent;
use GoetasWebservices\XML\WSDLReader\Events\ServiceEvent;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\Operation as BindingOperation;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationFault as BindingOperationFault;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationMessage as BindingOperationMessage;
use GoetasWebservices\XML\WSDLReader\Wsdl\Definitions;
use GoetasWebservices\XML\WSDLReader\Wsdl\Message;
use GoetasWebservices\XML\WSDLReader\Wsdl\Message\Part;
use GoetasWebservices\XML\WSDLReader\Wsdl\PortType;
use GoetasWebservices\XML\WSDLReader\Wsdl\PortType\Fault;
use GoetasWebservices\XML\WSDLReader\Wsdl\PortType\Operation;
use GoetasWebservices\XML\WSDLReader\Wsdl\PortType\Param;
use GoetasWebservices\XML\WSDLReader\Wsdl\PortType\Fault;
use GoetasWebservices\XML\WSDLReader\Wsdl\Service;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\Operation as BindingOperation;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationMessage as BindingOperationMessage;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationFault as BindingOperationFault;
use GoetasWebservices\XML\WSDLReader\Wsdl\Message\Part;
use GoetasWebservices\XML\WSDLReader\Wsdl\Service\Port;
use GoetasWebservices\XML\XSDReader\Utils\UrlUtils;
use GoetasWebservices\XML\XSDReader\Schema\Schema;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use GoetasWebservices\XML\WSDLReader\Events\DefinitionsEvent;
use GoetasWebservices\XML\XSDReader\Utils\UrlUtils;
use Symfony\Component\EventDispatcher\Event;
use GoetasWebservices\XML\WSDLReader\Events\MessageEvent;
use GoetasWebservices\XML\WSDLReader\Events\Message\PartEvent as MessagePartEvent;
use GoetasWebservices\XML\WSDLReader\Events\PortTypeEvent;
use GoetasWebservices\XML\WSDLReader\Events\PortType\OperationEvent;
use GoetasWebservices\XML\WSDLReader\Events\PortType\ParamEvent;
use GoetasWebservices\XML\WSDLReader\Events\PortType\FaultEvent;
use GoetasWebservices\XML\WSDLReader\Events\BindingEvent;
use GoetasWebservices\XML\WSDLReader\Events\Binding\OperationEvent as BindingOperationEvent;
use GoetasWebservices\XML\WSDLReader\Events\Binding\MessageEvent as BindingOperationMessageEvent;
use GoetasWebservices\XML\WSDLReader\Events\Binding\FaultEvent as BindingOperationFaultEvent;
use GoetasWebservices\XML\WSDLReader\Events\ServiceEvent;
use GoetasWebservices\XML\WSDLReader\Events\Service\PortEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class DefinitionsReader
{
Expand All @@ -59,8 +59,8 @@ class DefinitionsReader

public function __construct(SchemaReader $reader = null, EventDispatcherInterface $dispatcher = null)
{
$this->reader = $reader ? : new SchemaReader();
$this->dispatcher = $dispatcher ? : new EventDispatcher();
$this->reader = $reader ?: new SchemaReader();
$this->dispatcher = $dispatcher ?: new EventDispatcher();
}

/**
Expand All @@ -83,7 +83,7 @@ private function loop(DOMElement $node)
{
$childs = array();
foreach ($node->childNodes as $childNode) {
if (! ($childNode instanceof DOMElement) || $childNode->namespaceURI !== self::WSDL_NS) {
if (!($childNode instanceof DOMElement) || $childNode->namespaceURI !== self::WSDL_NS) {
continue;
}
$childs[] = $childNode;
Expand Down Expand Up @@ -137,10 +137,9 @@ private function rootNode(Definitions $definitions, DOMElement $node, Definition
break;
}
}
ksort($functions);
ksort($functions);
return array(
function () use ($functions, $definitions, $node)
{
function () use ($functions, $definitions, $node) {
$this->dispatcher->dispatch('definitions_start', new DefinitionsEvent($definitions, $node));
foreach ($functions as $subFunctions) {
foreach ($subFunctions as $function) {
Expand Down Expand Up @@ -177,8 +176,7 @@ private function loadBinding(Definitions $definitions, DOMElement $node)
break;
}
}
return function () use ($functions, $binding, $definitions, $node)
{
return function () use ($functions, $binding, $definitions, $node) {
list ($name, $ns) = self::splitParts($node, $node->getAttribute("type"));
$binding->setType($definitions->findPortType($name, $ns));

Expand Down Expand Up @@ -209,8 +207,7 @@ private function loadBindingOperation(Binding $binding, DOMElement $node)
break;
}
}
return function () use ($functions, $bindingOperation, $node)
{
return function () use ($functions, $bindingOperation, $node) {
$this->dispatcher->dispatch('binding.operation', new BindingOperationEvent($bindingOperation, $node));
foreach ($functions as $function) {
call_user_func($function);
Expand All @@ -228,9 +225,8 @@ private function loadBindingOperationMessage(BindingOperation $bindingOperation,
$bindingOperation->setOutput($message);
}

return function () use ($message, $node)
{
$this->dispatcher->dispatch('binding.operation.message', new BindingOperationMessageEvent($message, $node));
return function () use ($message, $node, $isInput) {
$this->dispatcher->dispatch('binding.operation.message', new BindingOperationMessageEvent($message, $node, $isInput ? 'input' : 'output'));
};
}

Expand All @@ -240,8 +236,7 @@ private function loadBindingOperationFault(BindingOperation $bindingOperation, D
$fault->setDocumentation($this->getDocumentation($node));
$bindingOperation->addFault($fault);

return function () use ($fault, $node)
{
return function () use ($fault, $node) {
$this->dispatcher->dispatch('binding.operation.fault', new BindingOperationFaultEvent($fault, $node));
};
}
Expand All @@ -260,8 +255,7 @@ private function loadService(Definitions $definitions, DOMElement $node)
break;
}
}
return function () use ($functions, $service, $node)
{
return function () use ($functions, $service, $node) {
$this->dispatcher->dispatch('service', new ServiceEvent($service, $node));
foreach ($functions as $function) {
call_user_func($function);
Expand All @@ -284,8 +278,7 @@ private function loadMessage(Definitions $definitions, DOMElement $node)
}
}

return function () use ($functions, $message, $node)
{
return function () use ($functions, $message, $node) {
$this->dispatcher->dispatch('message', new MessageEvent($message, $node));
foreach ($functions as $function) {
call_user_func($function);
Expand All @@ -298,8 +291,7 @@ private function loadPort(Service $service, DOMElement $node)
$port = new Port($service, $node->getAttribute("name"));
$port->setDocumentation($this->getDocumentation($node));
$service->addPort($port);
return function () use ($port, $service, $node)
{
return function () use ($port, $service, $node) {
list ($name, $ns) = self::splitParts($node, $node->getAttribute("binding"));
$port->setBinding($service->getDefinition()
->findBinding($name, $ns));
Expand All @@ -321,8 +313,7 @@ private function loadPortType(Definitions $definitions, DOMElement $node)
break;
}
}
return function () use ($functions, $port, $node)
{
return function () use ($functions, $port, $node) {
$this->dispatcher->dispatch('portType', new PortTypeEvent($port, $node));
foreach ($functions as $function) {
call_user_func($function);
Expand All @@ -334,7 +325,7 @@ private function loadPortTypeOperation(PortType $port, DOMElement $node)
{
$operation = new Operation($port, $node->getAttribute("name"));
$operation->setDocumentation($this->getDocumentation($node));
$operation->setParameterOrder($node->getAttribute("parameterOrder") ? : null);
$operation->setParameterOrder($node->getAttribute("parameterOrder") ?: null);
$port->addOperation($operation);

$functions = array();
Expand All @@ -351,8 +342,7 @@ private function loadPortTypeOperation(PortType $port, DOMElement $node)
break;
}
}
return function () use ($functions, $operation, $node)
{
return function () use ($functions, $operation, $node) {
$this->dispatcher->dispatch('portType.operation', new OperationEvent($operation, $node));
foreach ($functions as $function) {
call_user_func($function);
Expand All @@ -371,8 +361,7 @@ private function loadParam(Operation $operation, DOMElement $node, $in = true)
$operation->setOutput($param);
}

return function () use ($param, $operation, $node)
{
return function () use ($param, $operation, $node) {
list ($name, $ns) = self::splitParts($node, $node->getAttribute("message"));
$param->setMessage($operation->getDefinition()
->findMessage($name, $ns));
Expand All @@ -386,8 +375,7 @@ private function loadFault(Operation $operation, DOMElement $node)
$fault->setDocumentation($this->getDocumentation($node));
$operation->addFault($fault);

return function () use ($fault, $operation, $node)
{
return function () use ($fault, $operation, $node) {
list ($name, $ns) = self::splitParts($node, $node->getAttribute("message"));
$fault->setMessage($operation->getDefinition()->findMessage($name, $ns));

Expand All @@ -401,8 +389,7 @@ private function loadMessagePart(Message $message, DOMElement $node)
$part->setDocumentation($this->getDocumentation($node));
$message->addPart($part);

return function () use ($part, $node)
{
return function () use ($part, $node) {
if ($node->hasAttribute("element")) {
list ($name, $ns) = self::splitParts($node, $node->getAttribute("element"));
$part->setElement($part->getDefinition()
Expand Down Expand Up @@ -439,11 +426,11 @@ private function loadImport(Definitions $definitions, DOMElement $node)
$file = UrlUtils::resolveRelativeUrl($node->ownerDocument->documentURI, $node->getAttribute("location"));
if (isset($this->loadedFiles[$file])) {
$definitions->addImport($this->loadedFiles[$file]);
return function ()
{};
return function () {
};
}

if (! $node->getAttribute("namespace")) {
if (!$node->getAttribute("namespace")) {
$this->loadedFiles[$file] = $newDefinitions = $definitions;
} else {
$this->loadedFiles[$file] = $newDefinitions = new Definitions();
Expand All @@ -460,8 +447,7 @@ private function loadImport(Definitions $definitions, DOMElement $node)
$definitions->addImport($newDefinitions);
}

return function () use ($callbacks)
{
return function () use ($callbacks) {
foreach ($callbacks as $callback) {
call_user_func($callback);
}
Expand Down Expand Up @@ -496,7 +482,7 @@ public function readNode(\DOMElement $node, $file = 'wsdl.xsd')
public function readString($content, $file = 'wsdl.xsd')
{
$xml = new DOMDocument('1.0', 'UTF-8');
if (! $xml->loadXML($content)) {
if (!$xml->loadXML($content)) {
throw new IOException("Can't load the wsdl");
}
$xml->documentURI = $file;
Expand All @@ -523,7 +509,7 @@ public function readFile($file)
private function getDOM($file)
{
$xml = new DOMDocument('1.0', 'UTF-8');
if (! $xml->load($file)) {
if (!$xml->load($file)) {
throw new IOException("Can't load the file $file");
}
return $xml;
Expand Down
5 changes: 2 additions & 3 deletions src/Events/Binding/FaultEvent.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php
namespace GoetasWebservices\XML\WSDLReader\Events\Binding;

use Symfony\Component\EventDispatcher\Event;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\Operation;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationFault;
use GoetasWebservices\XML\WSDLReader\Events\WsdlEvent;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationFault;
use Symfony\Component\EventDispatcher\Event;

class FaultEvent extends WsdlEvent
{
Expand Down
30 changes: 23 additions & 7 deletions src/Events/Binding/MessageEvent.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
<?php
namespace GoetasWebservices\XML\WSDLReader\Events\Binding;

use Symfony\Component\EventDispatcher\Event;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\Operation;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationMessage;
use GoetasWebservices\XML\WSDLReader\Events\WsdlEvent;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationMessage;
use Symfony\Component\EventDispatcher\Event;

class MessageEvent extends WsdlEvent
{

protected $Fault;
protected $type;
protected $message;

public function __construct(OperationMessage $Fault, \DOMElement $node)
/**
* MessageEvent constructor.
* @param OperationMessage $message
* @param \DOMElement $node
* @param $type
*/
public function __construct(OperationMessage $message, \DOMElement $node, $type)
{
parent::__construct($node);
$this->Fault = $Fault;
$this->message = $message;
$this->type = $type;
}

/**
* @return \GoetasWebservices\XML\WSDLReader\Wsdl\Binding\OperationMessage
*/
public function getOperationMessage()
{
return $this->Fault;
return $this->message;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}
}


4 changes: 2 additions & 2 deletions src/Events/Binding/OperationEvent.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace GoetasWebservices\XML\WSDLReader\Events\Binding;

use Symfony\Component\EventDispatcher\Event;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\Operation;
use GoetasWebservices\XML\WSDLReader\Events\WsdlEvent;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding\Operation;
use Symfony\Component\EventDispatcher\Event;

class OperationEvent extends WsdlEvent
{
Expand Down
2 changes: 1 addition & 1 deletion src/Events/BindingEvent.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace GoetasWebservices\XML\WSDLReader\Events;

use Symfony\Component\EventDispatcher\Event;
use GoetasWebservices\XML\WSDLReader\Wsdl\Binding;
use Symfony\Component\EventDispatcher\Event;

class BindingEvent extends WsdlEvent
{
Expand Down
2 changes: 1 addition & 1 deletion src/Events/DefinitionsEvent.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace GoetasWebservices\XML\WSDLReader\Events;

use Symfony\Component\EventDispatcher\Event;
use GoetasWebservices\XML\WSDLReader\Wsdl\Definitions;
use Symfony\Component\EventDispatcher\Event;

class DefinitionsEvent extends WsdlEvent
{
Expand Down
4 changes: 2 additions & 2 deletions src/Events/Message/PartEvent.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace GoetasWebservices\XML\WSDLReader\Events\Message;

use Symfony\Component\EventDispatcher\Event;
use GoetasWebservices\XML\WSDLReader\Wsdl\Message\Part;
use GoetasWebservices\XML\WSDLReader\Events\WsdlEvent;
use GoetasWebservices\XML\WSDLReader\Wsdl\Message\Part;
use Symfony\Component\EventDispatcher\Event;

class PartEvent extends WsdlEvent
{
Expand Down
Loading

0 comments on commit 438f325

Please sign in to comment.