Skip to content

Commit 4127cf7

Browse files
committed
format source code using PHP CS fixer @PhpCsFixer rule
1 parent 3db47d6 commit 4127cf7

27 files changed

+329
-280
lines changed

.php_cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ $finder = PhpCsFixer\Finder::create()
77
return PhpCsFixer\Config::create()
88
->setUsingCache(false)
99
->setRules(array(
10-
'@PSR2' => true,
11-
'binary_operator_spaces' => true,
12-
'no_whitespace_in_blank_line' => true,
13-
'ternary_operator_spaces' => true,
14-
'cast_spaces' => true,
15-
'trailing_comma_in_multiline_array' => true
10+
'@PhpCsFixer' => true,
1611
))
1712
->setFinder($finder);

src/AbstractDocument.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace WsdlToPhp\WsdlHandler;
66

77
use DOMElement;
8-
use WsdlToPhp\DomHandler\ElementHandler;
9-
use WsdlToPhp\DomHandler\DomDocumentHandler;
108
use WsdlToPhp\DomHandler\AbstractDomDocumentHandler;
9+
use WsdlToPhp\DomHandler\DomDocumentHandler;
10+
use WsdlToPhp\DomHandler\ElementHandler;
1111
use WsdlToPhp\WsdlHandler\Tag\Tag;
1212

1313
abstract class AbstractDocument extends DomDocumentHandler
@@ -58,16 +58,6 @@ abstract class AbstractDocument extends DomDocumentHandler
5858
const TAG_UNION = 'union';
5959
const TAG_UNIQUE = 'unique';
6060

61-
protected function getElementHandler(DOMElement $element, AbstractDomDocumentHandler $domDocument, int $index = -1): ElementHandler
62-
{
63-
$handlerName = Tag::class;
64-
if (class_exists($elementNameClass = sprintf('%s\Tag\Tag%s', __NAMESPACE__, ucfirst(implode('', array_slice(explode(':', $element->nodeName), -1, 1)))))) {
65-
$handlerName = $elementNameClass;
66-
}
67-
68-
return new $handlerName($element, $domDocument, $index);
69-
}
70-
7161
public function getNamespaceUri(string $namespace): string
7262
{
7363
$rootElement = $this->getRootElement();
@@ -78,4 +68,14 @@ public function getNamespaceUri(string $namespace): string
7868

7969
return $uri;
8070
}
71+
72+
protected function getElementHandler(DOMElement $element, AbstractDomDocumentHandler $domDocument, int $index = -1): ElementHandler
73+
{
74+
$handlerName = Tag::class;
75+
if (class_exists($elementNameClass = sprintf('%s\Tag\Tag%s', __NAMESPACE__, ucfirst(implode('', array_slice(explode(':', $element->nodeName), -1, 1)))))) {
76+
$handlerName = $elementNameClass;
77+
}
78+
79+
return new $handlerName($element, $domDocument, $index);
80+
}
8181
}

src/Tag/AbstractTag.php

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,28 @@
55
namespace WsdlToPhp\WsdlHandler\Tag;
66

77
use DOMElement;
8-
use WsdlToPhp\DomHandler\NodeHandler;
9-
use WsdlToPhp\WsdlHandler\AbstractDocument;
108
use WsdlToPhp\DomHandler\AbstractAttributeHandler as Attribute;
11-
use WsdlToPhp\DomHandler\ElementHandler;
129
use WsdlToPhp\DomHandler\AbstractNodeHandler;
10+
use WsdlToPhp\DomHandler\ElementHandler;
11+
use WsdlToPhp\DomHandler\NodeHandler;
12+
use WsdlToPhp\WsdlHandler\AbstractDocument;
1313

1414
abstract class AbstractTag extends ElementHandler
1515
{
1616
const MAX_DEEP = 5;
1717

1818
/**
19-
* This method aims to get the parent element that matches a valid Wsdl element (aka struct)
20-
* @param bool $checkName
21-
* @param array $additionalTags
22-
* @param int $maxDeep
23-
* @param bool $strict
24-
* @return NodeHandler|null
19+
* This method aims to get the parent element that matches a valid Wsdl element (aka struct).
20+
*
21+
* @return null|NodeHandler
2522
*/
2623
public function getSuitableParent(bool $checkName = true, array $additionalTags = [], int $maxDeep = self::MAX_DEEP, bool $strict = false): ?AbstractNodeHandler
2724
{
2825
$parentNode = null;
2926
if ($this->getParent() instanceof AbstractNodeHandler) {
3027
$parentTags = $strict ? $additionalTags : $this->getSuitableParentTags($additionalTags);
3128
$parentNode = $this->getParent()->getNode();
32-
while ($maxDeep-- > 0 && ($parentNode instanceof DOMElement) && !empty($parentNode->nodeName) && (!preg_match('/' . implode('|', $parentTags) . '/i', $parentNode->nodeName) || ($checkName && preg_match('/' . implode('|', $parentTags) . '/i', $parentNode->nodeName) && (!$parentNode->hasAttribute('name') || $parentNode->getAttribute('name') === '')))) {
29+
while ($maxDeep-- > 0 && ($parentNode instanceof DOMElement) && !empty($parentNode->nodeName) && (!preg_match('/'.implode('|', $parentTags).'/i', $parentNode->nodeName) || ($checkName && preg_match('/'.implode('|', $parentTags).'/i', $parentNode->nodeName) && (!$parentNode->hasAttribute('name') || '' === $parentNode->getAttribute('name'))))) {
3330
$parentNode = $parentNode->parentNode;
3431
}
3532
if ($parentNode instanceof DOMElement) {
@@ -42,29 +39,6 @@ public function getSuitableParent(bool $checkName = true, array $additionalTags
4239
return $parentNode;
4340
}
4441

45-
protected function getSuitableParentTags(array $additionalTags = []): array
46-
{
47-
return array_merge([
48-
AbstractDocument::TAG_ELEMENT,
49-
AbstractDocument::TAG_ATTRIBUTE,
50-
AbstractDocument::TAG_SIMPLE_TYPE,
51-
AbstractDocument::TAG_COMPLEX_TYPE,
52-
], $additionalTags);
53-
}
54-
55-
protected function getStrictParent(string $name, bool $checkName = false): ?AbstractNodeHandler
56-
{
57-
$parent = $this->getSuitableParent($checkName, [
58-
$name,
59-
], self::MAX_DEEP, true);
60-
61-
if ($parent instanceof AbstractNodeHandler && $parent->getName() === $name) {
62-
return $parent;
63-
}
64-
65-
return null;
66-
}
67-
6842
public function hasAttributeName(): bool
6943
{
7044
return $this->hasAttribute(Attribute::ATTRIBUTE_NAME);
@@ -94,4 +68,27 @@ public function getValueAttributeValue(bool $withNamespace = false, bool $within
9468
{
9569
return $this->getAttribute(Attribute::ATTRIBUTE_VALUE) instanceof Attribute ? $this->getAttribute(Attribute::ATTRIBUTE_VALUE)->getValue($withNamespace, $withinItsType, $asType) : '';
9670
}
71+
72+
protected function getSuitableParentTags(array $additionalTags = []): array
73+
{
74+
return array_merge([
75+
AbstractDocument::TAG_ELEMENT,
76+
AbstractDocument::TAG_ATTRIBUTE,
77+
AbstractDocument::TAG_SIMPLE_TYPE,
78+
AbstractDocument::TAG_COMPLEX_TYPE,
79+
], $additionalTags);
80+
}
81+
82+
protected function getStrictParent(string $name, bool $checkName = false): ?AbstractNodeHandler
83+
{
84+
$parent = $this->getSuitableParent($checkName, [
85+
$name,
86+
], self::MAX_DEEP, true);
87+
88+
if ($parent instanceof AbstractNodeHandler && $parent->getName() === $name) {
89+
return $parent;
90+
}
91+
92+
return null;
93+
}
9794
}

src/Tag/AbstractTagImport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function getLocationAttributeValue(): string
2222
$location = $this->getAttributeValue(self::ATTRIBUTE_SCHEMA_LOCATION_, true);
2323
}
2424

25-
if (!empty($location) && mb_substr($location, 0, 2) === './') {
25+
if (!empty($location) && './' === mb_substr($location, 0, 2)) {
2626
$location = mb_substr($location, 2);
2727
}
2828

src/Tag/Tag.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public function getFirstRestrictionChild(): ?TagRestriction
2020
}
2121

2222
/**
23-
* Checks if the given tag is the same direct parent of this current tag
24-
* @param AbstractTag $tag
25-
* @return bool
23+
* Checks if the given tag is the same direct parent of this current tag.
2624
*/
2725
public function isTheParent(AbstractTag $tag): bool
2826
{

src/Tag/TagAttributeGroup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function getReferencingElements(): array
1212
$attributeGroups = $this->getDomDocumentHandler()->getElementsByNameAndAttributes('attributeGroup', [
1313
'ref' => sprintf('*:%s', $this->getAttributeName()),
1414
]);
15-
/**
15+
/*
1616
* In case of a referencing element that use this attributeGroup that is not namespaced,
1717
* use the non namespaced value
1818
*/
@@ -23,7 +23,7 @@ public function getReferencingElements(): array
2323
}
2424
foreach ($attributeGroups as $attributeGroup) {
2525
$parent = $attributeGroup->getSuitableParent();
26-
/**
26+
/*
2727
* In this case, this means the attribute is included in another attribute group,
2828
* this means we must climb to its parent recursively until we find the elements referencing the top attributeGroup tag
2929
*/

src/Tag/TagChoice.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ public function getChildrenElements(): array
2121
return $children;
2222
}
2323

24+
public static function getChildrenElementsTags(): array
25+
{
26+
return [
27+
AbstractDocument::TAG_ELEMENT,
28+
AbstractDocument::TAG_GROUP,
29+
AbstractDocument::TAG_CHOICE,
30+
AbstractDocument::TAG_ANY,
31+
];
32+
}
33+
34+
public static function getForbiddenParentTags(): array
35+
{
36+
return [
37+
AbstractDocument::TAG_COMPLEX_TYPE,
38+
];
39+
}
40+
2441
protected function getFilteredChildrenByName(string $tagName): array
2542
{
2643
return array_filter($this->getChildrenByName($tagName), [
@@ -31,9 +48,7 @@ protected function getFilteredChildrenByName(string $tagName): array
3148

3249
/**
3350
* This must ensure the current element, based on its tagName is not contained by another element than the choice.
34-
* If it is contained by another element, then it is child/property of its parent element and does not belong to the choice elements
35-
* @param AbstractTag $child
36-
* @return bool
51+
* If it is contained by another element, then it is child/property of its parent element and does not belong to the choice elements.
3752
*/
3853
protected function filterFoundChildren(AbstractTag $child): bool
3954
{
@@ -46,21 +61,4 @@ protected function filterFoundChildren(AbstractTag $child): bool
4661

4762
return (bool) $valid;
4863
}
49-
50-
public static function getChildrenElementsTags(): array
51-
{
52-
return [
53-
AbstractDocument::TAG_ELEMENT,
54-
AbstractDocument::TAG_GROUP,
55-
AbstractDocument::TAG_CHOICE,
56-
AbstractDocument::TAG_ANY,
57-
];
58-
}
59-
60-
public static function getForbiddenParentTags(): array
61-
{
62-
return [
63-
AbstractDocument::TAG_COMPLEX_TYPE,
64-
];
65-
}
6664
}

src/Tag/TagDocumentation.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ public function getContent(): string
1919
* This case is managed first because enumerations are contained by elements and
2020
* the method could climb to its parent without stopping on the enumeration tag.
2121
* Indeed, depending on the node, it may contain or not the attribute named "name" so we have to split each case.
22-
* @param bool $checkName
23-
* @param array $additionalTags
24-
* @param int $maxDeep
25-
* @param bool $strict
26-
* @return AbstractNodeHandler|null
2722
*/
2823
public function getSuitableParent(bool $checkName = true, array $additionalTags = [], int $maxDeep = self::MAX_DEEP, bool $strict = false): ?AbstractNodeHandler
2924
{

src/Tag/TagEnumeration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getRestrictionParent(): ?TagRestriction
2323

2424
public function getRestrictionParentType(): string
2525
{
26-
/** @var TagRestriction|null $restrictionParent */
26+
/** @var null|TagRestriction $restrictionParent */
2727
$restrictionParent = $this->getRestrictionParent();
2828

2929
return $restrictionParent ? $restrictionParent->getAttributeBase() : '';

src/Tag/TagHeader.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace WsdlToPhp\WsdlHandler\Tag;
66

7-
use WsdlToPhp\WsdlHandler\AbstractDocument;
87
use WsdlToPhp\DomHandler\AbstractAttributeHandler as Attribute;
8+
use WsdlToPhp\WsdlHandler\AbstractDocument;
99

1010
class TagHeader extends AbstractTagOperationElement
1111
{
@@ -42,6 +42,7 @@ public function getPartTag(): ?TagPart
4242
public function getHeaderType(): string
4343
{
4444
$part = $this->getPartTag();
45+
4546
return $part instanceof TagPart ? $part->getFinalType() : '';
4647
}
4748

@@ -62,6 +63,11 @@ public function getHeaderNamespace(): string
6263
return $namespace;
6364
}
6465

66+
public function getHeaderRequired(): string
67+
{
68+
return $this->getAttributeRequired() ? self::REQUIRED_HEADER : self::OPTIONAL_HEADER;
69+
}
70+
6571
protected function getHeaderNamespaceFromPart(): string
6672
{
6773
$part = $this->getPartTag();
@@ -86,9 +92,4 @@ protected function getHeaderNamespaceFromMessage(): string
8692

8793
return $namespace;
8894
}
89-
90-
public function getHeaderRequired(): string
91-
{
92-
return $this->getAttributeRequired() ? self::REQUIRED_HEADER : self::OPTIONAL_HEADER;
93-
}
9495
}

0 commit comments

Comments
 (0)