@@ -28,7 +28,12 @@ public function parse(): array
2828 $ xmlParser ->autoRemoveXPathNamespaces ();
2929
3030 $ finder = new \Symfony \Component \Finder \Finder ();
31- $ finder ->files ()->in ($ this ->xml_path );
31+
32+ if (\file_exists ($ this ->xml_path ) && !\is_dir ($ this ->xml_path )) {
33+ $ finder ->files ()->in (\dirname ($ this ->xml_path ))->name (\basename ($ this ->xml_path ));
34+ } else {
35+ $ finder ->files ()->in ($ this ->xml_path );
36+ }
3237
3338 $ data = [[]];
3439 foreach ($ finder as $ file ) {
@@ -40,12 +45,15 @@ public function parse(): array
4045 $ absoluteFilePath = $ file ->getPath () . \DIRECTORY_SEPARATOR . $ fileName ;
4146 $ content = $ file ->getContents ();
4247
48+ $ contentMethodKeyword = 'methodsynopsis ' ;
4349 \preg_match ('#<methodsynopsis>.*</methodsynopsis>#Uis ' , $ content , $ contentMethod );
4450 $ contentMethod = $ contentMethod [0 ] ?? null ;
4551
52+ $ contentMethodOopKeyword = 'methodsynopsis ' ;
4653 \preg_match ('#<methodsynopsis role="oop">.*</methodsynopsis>#Uis ' , $ content , $ contentMethodOop );
4754 $ contentMethodOop = $ contentMethodOop [0 ] ?? null ;
4855
56+ $ contentConstructorKeyword = 'constructorsynopsis ' ;
4957 \preg_match ('#<constructorsynopsis>.*</constructorsynopsis>#Uis ' , $ content , $ contentConstructor );
5058 $ contentConstructor = $ contentConstructor [0 ] ?? null ;
5159
@@ -55,17 +63,17 @@ public function parse(): array
5563
5664 if ($ contentMethod ) {
5765 $ methodsynopsis = $ xmlParser ->loadXml ($ contentMethod );
58- $ data [] = $ this ->findTypes ($ methodsynopsis , $ absoluteFilePath );
66+ $ data [] = $ this ->findTypes ($ methodsynopsis , $ absoluteFilePath, $ contentMethodKeyword );
5967 }
6068
6169 if ($ contentMethodOop ) {
6270 $ methodsynopsisOop = $ xmlParser ->loadXml ($ contentMethodOop );
63- $ data [] = $ this ->findTypes ($ methodsynopsisOop , $ absoluteFilePath );
71+ $ data [] = $ this ->findTypes ($ methodsynopsisOop , $ absoluteFilePath, $ contentMethodOopKeyword );
6472 }
6573
6674 if ($ contentConstructor ) {
6775 $ constructorsynopsis = $ xmlParser ->loadXml ($ contentConstructor );
68- $ data [] = $ this ->findTypes ($ constructorsynopsis , $ absoluteFilePath );
76+ $ data [] = $ this ->findTypes ($ constructorsynopsis , $ absoluteFilePath, $ contentConstructorKeyword );
6977 }
7078 }
7179
@@ -75,6 +83,7 @@ public function parse(): array
7583 /**
7684 * @param \voku\helper\XmlDomParser $xmlParser
7785 * @param string $absoluteFilePath
86+ * @param string $xmlWrapperElement
7887 *
7988 * @return array
8089 *
@@ -86,22 +95,23 @@ public function parse(): array
8695 */
8796 private function findTypes (
8897 \voku \helper \XmlDomParser $ xmlParser ,
89- string $ absoluteFilePath
98+ string $ absoluteFilePath ,
99+ string $ xmlWrapperElement
90100 ): array {
91101 // init
92102 $ data = [];
93103
94- $ name = $ xmlParser ->findOne ('// methodname ' )->text ();
104+ $ name = $ xmlParser ->findOne ('methodname ' )->text ();
95105 $ data [$ name ]['absoluteFilePath ' ] = $ absoluteFilePath ;
96106
97107 $ returnTypesArray = [];
98- $ returnTypesTmp = $ xmlParser ->findMultiOrFalse (' type.union type ' );
108+ $ returnTypesTmp = $ xmlParser ->findMultiOrFalse ($ xmlWrapperElement . ' > type.union > type ' );
99109 if ($ returnTypesTmp !== false ) {
100110 foreach ($ returnTypesTmp as $ returnTypeTmp ) {
101111 $ returnTypeText = $ returnTypeTmp ->text ();
102112 $ returnTypesArray [$ returnTypeText ] = \ltrim ($ returnTypeText , '\\' );
103113 }
104- } elseif (($ returnTypeTmp = $ xmlParser ->findOneOrFalse (' type ' )) !== false ) {
114+ } elseif (($ returnTypeTmp = $ xmlParser ->findOneOrFalse ($ xmlWrapperElement . ' > type ' )) !== false ) {
105115 $ returnTypeText = $ returnTypeTmp ->text ();
106116 $ returnTypesArray [$ returnTypeText ] = \ltrim ($ returnTypeText , '\\' );
107117 }
@@ -113,7 +123,7 @@ private function findTypes(
113123 $ paramName = $ param ->findOne ('parameter ' )->text ();
114124 $ paramTypesArray = [];
115125
116- $ paramTypesTmp = $ param ->findMultiOrFalse ('type.union type ' );
126+ $ paramTypesTmp = $ param ->findMultiOrFalse ('type.union > type ' );
117127 if ($ paramTypesTmp !== false ) {
118128 foreach ($ paramTypesTmp as $ paramTypeTmp ) {
119129 $ paramTypeText = $ paramTypeTmp ->text ();
0 commit comments