@@ -20,6 +20,19 @@ public function getAttributeElement(bool $returnValue = true)
2020 return $ this ->getAttributeMixedValue (self ::ATTRIBUTE_ELEMENT , $ returnValue );
2121 }
2222
23+ public function getMatchingElement (): ?TagElement
24+ {
25+ $ element = null ;
26+ $ elementName = $ this ->getAttributeElement ();
27+ if (!empty ($ elementName )) {
28+ $ element = $ this ->getDomDocumentHandler ()->getElementByNameAndAttributes (AbstractDocument::TAG_ELEMENT , [
29+ 'name ' => $ elementName ,
30+ ], true );
31+ }
32+
33+ return $ element ;
34+ }
35+
2336 /**
2437 * @return null|AttributeHandler|int|string
2538 */
@@ -32,16 +45,11 @@ public function getFinalType(): string
3245 {
3346 $ type = $ this ->getAttributeType ();
3447 if (empty ($ type )) {
35- $ elementName = $ this ->getAttributeElement ();
36- if (!empty ($ elementName )) {
37- $ element = $ this ->getDomDocumentHandler ()->getElementByNameAndAttributes (AbstractDocument::TAG_ELEMENT , [
38- 'name ' => $ elementName ,
39- ], true );
40- if ($ element instanceof TagElement && $ element ->hasAttribute (self ::ATTRIBUTE_TYPE )) {
41- $ type = $ element ->getAttribute (self ::ATTRIBUTE_TYPE )->getValue ();
42- } else {
43- $ type = $ elementName ;
44- }
48+ $ element = $ this ->getMatchingElement ();
49+ if ($ element instanceof TagElement && $ element ->hasAttribute (self ::ATTRIBUTE_TYPE )) {
50+ $ type = $ element ->getAttribute (self ::ATTRIBUTE_TYPE )->getValue ();
51+ } else {
52+ $ type = $ this ->getAttributeElement ();
4553 }
4654 }
4755
@@ -61,13 +69,13 @@ public function getFinalName(): string
6169 public function getFinalNamespace (): ?string
6270 {
6371 $ attribute = $ this ->getAttributeType (false );
64- if (!empty ($ attribute )) {
65- return $ attribute -> getValueNamespace () ;
72+ if ($ attribute instanceof AttributeHandler && !empty ($ namespace = $ attribute-> getValueNamespace () )) {
73+ return $ namespace ;
6674 }
6775
6876 $ attribute = $ this ->getAttributeElement (false );
69- if (!empty ($ attribute )) {
70- return $ attribute -> getValueNamespace () ;
77+ if ($ attribute instanceof AttributeHandler && !empty ($ namespace = $ attribute-> getValueNamespace () )) {
78+ return $ namespace ;
7179 }
7280
7381 return null ;
0 commit comments