1 | <?php |
||
15 | class XmlParserService |
||
16 | { |
||
17 | /** |
||
18 | * @var \DOMElement |
||
19 | */ |
||
20 | protected $element; |
||
21 | |||
22 | /** |
||
23 | * @var XmlConvertibleInterface[] |
||
24 | */ |
||
25 | protected $aliases; |
||
26 | |||
27 | /** |
||
28 | * XmlParserService constructor. |
||
29 | * @param $document |
||
30 | * @param array $aliases |
||
31 | */ |
||
32 | 15 | public function __construct($document, array $aliases = []) |
|
38 | |||
39 | 8 | public function __clone() |
|
43 | |||
44 | /** |
||
45 | * @return XmlConvertibleInterface |
||
46 | */ |
||
47 | 10 | public function convert() |
|
64 | |||
65 | /** |
||
66 | * @param XmlConvertibleInterface $object |
||
67 | * @return $this |
||
68 | */ |
||
69 | 8 | public function convertChildren(XmlConvertibleInterface &$object) |
|
82 | |||
83 | 9 | public function convertAttributes(XmlConvertibleInterface &$object) |
|
100 | |||
101 | /** |
||
102 | * @param \DOMNode|\DOMDocument $document |
||
103 | * @return $this |
||
104 | */ |
||
105 | 12 | public function setDocument($document) |
|
106 | { |
||
107 | 12 | if ($document instanceof \DOMDocument) { |
|
108 | 8 | return $this->setDocument($document->firstChild); |
|
109 | } |
||
110 | |||
111 | 12 | if (!$document instanceof \DOMNode) { |
|
112 | 1 | throw new \InvalidArgumentException("Document must be instance of DOMElement or DOMNode"); |
|
113 | } |
||
114 | 11 | $this->element = $document; |
|
|
|||
115 | |||
116 | 11 | return $this; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return \DOMElement |
||
121 | */ |
||
122 | 1 | public function getDocument() |
|
123 | { |
||
124 | 1 | return $this->element; |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * @param XmlConvertibleInterface[]|string $aliases |
||
129 | * @return $this |
||
130 | */ |
||
131 | 15 | public function setAliases(array $aliases = []) |
|
145 | |||
146 | /** |
||
147 | * @return XmlConvertibleInterface[] |
||
148 | */ |
||
149 | 1 | public function getAliases() |
|
150 | { |
||
151 | 1 | return $this->aliases; |
|
152 | } |
||
153 | |||
154 | /** |
||
155 | * @param string|XmlConvertibleInterface $element |
||
156 | * @return XmlConvertibleInterface |
||
157 | */ |
||
158 | 13 | protected function mapAlias($element) |
|
172 | |||
173 | /** |
||
174 | * @param string|integer $key |
||
175 | * @param XmlConvertibleInterface $element |
||
176 | * @return string |
||
177 | */ |
||
178 | 10 | protected function mapKey($key, XmlConvertibleInterface $element): string |
|
179 | { |
||
180 | 10 | return is_numeric($key) |
|
181 | 1 | ? $element->getXmlElementName() |
|
182 | 10 | : $key; |
|
183 | } |
||
184 | |||
185 | /** |
||
186 | * @param string $key |
||
187 | * @param XmlConvertibleInterface $element |
||
188 | * @return bool |
||
189 | */ |
||
190 | 10 | protected function getIsAliasMatch(string $key, XmlConvertibleInterface $element): bool |
|
204 | } |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.