Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds rector and the suggested fixes for the config #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
])
// uncomment to reach your current PHP version
->withPhpSets(php81: true)
->withPreparedSets(
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
);
50 changes: 14 additions & 36 deletions src/Elements/ComplexType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Dgame\Wsdl\Elements;

use DOMElement;
Expand All @@ -19,8 +21,6 @@ final class ComplexType extends SimpleType

/**
* @param ComplexType|null $complex
*
* @return bool
*/
public function isComplexType(self &$complex = null): bool
{
Expand All @@ -29,27 +29,20 @@ public function isComplexType(self &$complex = null): bool
return true;
}

/**
* @return bool
*/
public function isAbstract(): bool
{
return $this->hasAttribute('abstract')
&& filter_var($this->getAttribute('abstract'), FILTER_VALIDATE_BOOLEAN);
}

/**
* @return bool
*/
public function hasExtensions(): bool
{
$extensions = $this->getExtensions();

return !empty($extensions);
return $extensions !== [];
}

/**
* @return Extension
* @throws \Throwable
*/
public function getFirstExtension(): Extension
Expand All @@ -61,21 +54,11 @@ public function getFirstExtension(): Extension
return reset($extensions);
}

/**
* @param string $name
*
* @return bool
*/
public function hasExtensionWithName(string $name): bool
{
return array_key_exists($name, $this->extensions);
}

/**
* @param string $name
*
* @return Extension
*/
public function getExtensionByName(string $name): Extension
{
return $this->extensions[$name];
Expand All @@ -86,13 +69,13 @@ public function getExtensionByName(string $name): Extension
*/
public function getExtensions(): array
{
if (!empty($this->extensions)) {
if ($this->extensions !== []) {
return $this->extensions;
}

$nodes = $this->getDomElement()->getElementsByTagName('extension');
for ($i = 0, $c = $nodes->length; $i < $c; $i++) {
$node = $nodes->item($i);
$domNodeList = $this->getDomElement()->getElementsByTagName('extension');
for ($i = 0, $c = $domNodeList->length; $i < $c; ++$i) {
$node = $domNodeList->item($i);
$extension = new Extension($node, $node->getAttribute('base'));

$this->extensions[$extension->getBase()] = $extension;
Expand All @@ -102,33 +85,28 @@ public function getExtensions(): array
}

/**
* @param string $name
*
* @return Element
* @throws \Throwable
*/
public function getElementByName(string $name): Element
{
$elements = $this->getElementsByName($name);

enforce(count($elements) !== 0)->orThrow('There are no nodes with name %s', $name);
enforce($elements !== [])->orThrow('There are no nodes with name %s', $name);
enforce(count($elements) === 1)->orThrow('There are multiple nodes with name %s', $name);

return array_pop($elements);
}

/**
* @param string $name
*
* @return Element[]
*/
public function getElementsByName(string $name): array
{
$elements = [];

$nodes = $this->getDomElement()->getElementsByTagName($name);
for ($i = 0, $c = $nodes->length; $i < $c; $i++) {
$node = $nodes->item($i);
$domNodeList = $this->getDomElement()->getElementsByTagName($name);
for ($i = 0, $c = $domNodeList->length; $i < $c; ++$i) {
$node = $domNodeList->item($i);

$elements[$node->getAttribute('name')] = new self($node);
}
Expand All @@ -141,11 +119,11 @@ public function getElementsByName(string $name): array
*/
public function getElements(): array
{
$nodes = $this->getDomElement()->getElementsByTagName('element');
$domNodeList = $this->getDomElement()->getElementsByTagName('element');

$elements = [];
for ($i = 0, $c = $nodes->length; $i < $c; $i++) {
$node = $nodes->item($i);
for ($i = 0, $c = $domNodeList->length; $i < $c; ++$i) {
$node = $domNodeList->item($i);

$elements[] = new Element($node);
}
Expand Down
65 changes: 20 additions & 45 deletions src/Elements/Element.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Dgame\Wsdl\Elements;

use DOMElement;
Expand All @@ -11,75 +13,49 @@
*/
class Element
{
/**
* @var DOMElement
*/
private DOMElement $element;

/**
* Element constructor.
*
* @param DOMElement $element
*/
public function __construct(DOMElement $element)
public function __construct(private readonly DOMElement $domElement)
{
$this->element = $element;
}

/**
* @param SimpleType|null $simple
*
* @return bool
* @param SimpleType|null $simpleType
*/
public function isSimpleType(SimpleType &$simple = null): bool
public function isSimpleType(SimpleType &$simpleType = null): bool
{
$simple = null;
$simpleType = null;

return false;
}

/**
* @param ComplexType|null $complex
*
* @return bool
* @param ComplexType|null $complexType
*/
public function isComplexType(ComplexType &$complex = null): bool
public function isComplexType(ComplexType &$complexType = null): bool
{
$complex = null;
$complexType = null;

return false;
}

/**
* @param string $name
*
* @return bool
*/
final public function hasAttribute(string $name): bool
{
return $this->element->hasAttribute($name);
return $this->domElement->hasAttribute($name);
}

/**
* @param string $name
*
* @return string
*/
final public function getAttribute(string $name): string
{
return $this->element->getAttribute($name);
return $this->domElement->getAttribute($name);
}

/**
* @return DOMElement
*/
final public function getDomElement(): DOMElement
{
return $this->element;
return $this->domElement;
}

/**
* @return SimpleType
* @throws \Throwable
*/
final public function getSimpleType(): SimpleType
Expand All @@ -88,15 +64,14 @@ final public function getSimpleType(): SimpleType
return $simple;
}

$nodes = $this->getDomElement()->getElementsByTagName('simpleType');
enforce($nodes->length !== 0)->orThrow('There are no nodes with name Simple-Types');
enforce($nodes->length === 1)->orThrow('There are multiple nodes with name Simple-Types');
$domNodeList = $this->getDomElement()->getElementsByTagName('simpleType');
enforce($domNodeList->length !== 0)->orThrow('There are no nodes with name Simple-Types');
enforce($domNodeList->length === 1)->orThrow('There are multiple nodes with name Simple-Types');

return new SimpleType($nodes->item(0));
return new SimpleType($domNodeList->item(0));
}

/**
* @return ComplexType
* @throws \Throwable
*/
final public function getComplexType(): ComplexType
Expand All @@ -105,10 +80,10 @@ final public function getComplexType(): ComplexType
return $complex;
}

$nodes = $this->getDomElement()->getElementsByTagName('complexType');
enforce($nodes->length !== 0)->orThrow('There are no nodes with name Complex-Types');
enforce($nodes->length === 1)->orThrow('There are multiple nodes with name Complex-Types');
$domNodeList = $this->getDomElement()->getElementsByTagName('complexType');
enforce($domNodeList->length !== 0)->orThrow('There are no nodes with name Complex-Types');
enforce($domNodeList->length === 1)->orThrow('There are multiple nodes with name Complex-Types');

return new ComplexType($nodes->item(0));
return new ComplexType($domNodeList->item(0));
}
}
38 changes: 7 additions & 31 deletions src/Elements/Extension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Dgame\Wsdl\Elements;

use DOMElement;
Expand All @@ -10,63 +12,37 @@
*/
final class Extension
{
/**
* @var string
*/
private string $base;
/**
* @var string
*/

private string $prefix;
/**
* @var DOMElement
*/
private DOMElement $element;

/**
* Extension constructor.
*
* @param DOMElement $element
* @param string $extension
*/
public function __construct(DOMElement $element, string $extension)
public function __construct(private readonly DOMElement $domElement, string $extension)
{
$this->element = $element;

if (str_contains($extension, ':')) {
[$this->prefix, $this->base] = explode(':', $extension);
} else {
$this->base = $extension;
}
}

/**
* @return string
*/
public function getPrefixedName(): string
{
return sprintf('%s:%s', $this->prefix, $this->base);
}

/**
* @return DOMElement
*/
public function getDomElement(): DOMElement
{
return $this->element;
return $this->domElement;
}

/**
* @return string
*/
public function getBase(): string
{
return $this->base;
}

/**
* @return string
*/
public function getPrefix(): string
{
return $this->prefix;
Expand All @@ -79,8 +55,8 @@ public function getElements(): array
{
$elements = [];

$nodes = $this->getDomElement()->getElementsByTagName('element');
for ($i = 0, $c = $nodes->length; $i < $c; $i++) {
$nodes = $this->domElement->getElementsByTagName('element');
for ($i = 0, $c = $nodes->length; $i < $c; ++$i) {
$node = $nodes->item($i);

$elements[] = new Element($node);
Expand Down
Loading