1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace WsdlToPhp\WsdlHandler\Tag; |
6
|
|
|
|
7
|
|
|
use WsdlToPhp\DomHandler\AttributeHandler; |
8
|
|
|
use WsdlToPhp\WsdlHandler\AbstractDocument; |
9
|
|
|
|
10
|
|
|
class TagPart extends Tag |
11
|
|
|
{ |
12
|
|
|
public const ATTRIBUTE_ELEMENT = 'element'; |
13
|
|
|
public const ATTRIBUTE_TYPE = 'type'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @return null|AttributeHandler|int|string |
17
|
|
|
*/ |
18
|
14 |
|
public function getAttributeElement(bool $returnValue = true) |
19
|
|
|
{ |
20
|
14 |
|
return $this->getAttributeMixedValue(self::ATTRIBUTE_ELEMENT, $returnValue); |
21
|
|
|
} |
22
|
|
|
|
23
|
8 |
|
public function getMatchingElement(): ?TagElement |
24
|
|
|
{ |
25
|
8 |
|
$element = null; |
26
|
8 |
|
$elementName = $this->getAttributeElement(); |
27
|
8 |
|
if (!empty($elementName)) { |
28
|
8 |
|
$element = $this->getDomDocumentHandler()->getElementByNameAndAttributes(AbstractDocument::TAG_ELEMENT, [ |
29
|
8 |
|
'name' => $elementName, |
30
|
8 |
|
], true); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
8 |
|
return $element; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return null|AttributeHandler|int|string |
38
|
|
|
*/ |
39
|
12 |
|
public function getAttributeType(bool $returnValue = true) |
40
|
|
|
{ |
41
|
12 |
|
return $this->getAttributeMixedValue(self::ATTRIBUTE_TYPE, $returnValue); |
42
|
|
|
} |
43
|
|
|
|
44
|
4 |
|
public function getFinalType(): string |
45
|
|
|
{ |
46
|
4 |
|
$type = $this->getAttributeType(); |
47
|
4 |
|
if (empty($type)) { |
48
|
4 |
|
$element = $this->getMatchingElement(); |
49
|
4 |
|
if ($element instanceof TagElement && $element->hasAttribute(self::ATTRIBUTE_TYPE)) { |
50
|
2 |
|
$type = $element->getAttribute(self::ATTRIBUTE_TYPE)->getValue(); |
51
|
|
|
} else { |
52
|
2 |
|
$type = $this->getAttributeElement(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
4 |
|
return $type; |
57
|
|
|
} |
58
|
|
|
|
59
|
2 |
|
public function getFinalName(): string |
60
|
|
|
{ |
61
|
2 |
|
$name = $this->getAttributeType(); |
62
|
2 |
|
if (empty($name)) { |
63
|
2 |
|
$name = $this->getAttributeElement(); |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
return $name; |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
6 |
|
public function getFinalNamespace(): ?string |
70
|
|
|
{ |
71
|
6 |
|
$attribute = $this->getAttributeType(false); |
72
|
6 |
|
if ($attribute instanceof AttributeHandler && !empty($namespace = $attribute->getValueNamespace())) { |
73
|
|
|
return $namespace; |
74
|
|
|
} |
75
|
|
|
|
76
|
6 |
|
$attribute = $this->getAttributeElement(false); |
77
|
6 |
|
if ($attribute instanceof AttributeHandler && !empty($namespace = $attribute->getValueNamespace())) { |
78
|
4 |
|
return $namespace; |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
return null; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return null|AttributeHandler|int|string |
86
|
|
|
*/ |
87
|
14 |
|
protected function getAttributeMixedValue(string $attributeName, bool $returnValue = true) |
88
|
|
|
{ |
89
|
14 |
|
$value = $this->getAttribute($attributeName); |
90
|
14 |
|
if ($returnValue) { |
91
|
10 |
|
$value = $value instanceof AttributeHandler ? $value->getValue() : null; |
92
|
|
|
} |
93
|
|
|
|
94
|
14 |
|
return $value; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.