@@ -98,22 +98,13 @@ private static function findClasses($path)
9898 {
9999 $ contents = file_get_contents ($ path );
100100 try {
101- //$nbResults = preg_match_all('{\b(?:class|interface|trait)\b}i', $contents);
102- //$nbResults = preg_match_all('{\b(?:class)\b}i', $contents, $results, PREG_OFFSET_CAPTURE);
103-
104-
105- /*$nbResults = preg_match_all('{\b(?:class)\b}i', $contents);
106- if ($nbResults == 0) {
107- return array();
108- }*/
109-
110101 // Let's trim the content after the last "class" keyword line.
111102 $ classKeywordPos = strrpos ($ contents , 'class ' );
112103 if ($ classKeywordPos === false ) {
113104 return array ();
114105 }
115106 //$classKeywordPos = $results[0][count($results[0])-1][1];
116-
107+
117108 // Jump 2 newlines after the last class keyword.
118109 if (strlen ($ contents ) > $ classKeywordPos +6 ) {
119110 $ newLinePos = strpos ($ contents , "\n" , $ classKeywordPos +6 );
@@ -124,21 +115,20 @@ private static function findClasses($path)
124115 }
125116 }
126117 }
127-
128- // Let's ignore any warning because we are cutting in the middle of a PHP file and we might cut in a
118+
119+ // Let's ignore any warning because we are cutting in the middle of a PHP file and we might cut in a
129120 // comment.
130121 $ currentErrorReporting = error_reporting (E_ALL & ~E_COMPILE_WARNING );
131122 $ tokens = token_get_all ($ contents );
132123 error_reporting ($ currentErrorReporting );
133124 } catch (\Exception $ e ) {
134125 throw new \RuntimeException ('Could not scan for classes inside ' .$ path .": \n" .$ e ->getMessage (), 0 , $ e );
135126 }
136- $ T_TRAIT = version_compare (PHP_VERSION , '5.4 ' , '< ' ) ? -1 : T_TRAIT ;
137127
138128 $ classes = array ();
139129
140130 $ namespace = '' ;
141-
131+
142132 for ($ i = 0 , $ max = count ($ tokens ); $ i < $ max ; $ i ++) {
143133 $ token = $ tokens [$ i ];
144134
@@ -153,17 +143,17 @@ private static function findClasses($path)
153143 $ namespace = '' ;
154144 // If there is a namespace, extract it
155145 while (($ t = $ tokens [++$ i ]) && is_array ($ t )) {
156- if (in_array ($ t [0 ], array (T_STRING , T_NS_SEPARATOR ))) {
146+ if (in_array ($ t [0 ], array (T_STRING , T_NS_SEPARATOR , T_NAME_QUALIFIED , T_NAME_FULLY_QUALIFIED ))) {
157147 $ namespace .= $ t [1 ];
158148 }
159149 }
160150 $ namespace .= '\\' ;
161151 break ;
162152 case T_CLASS :
163153 //case T_INTERFACE:
164- //case $ T_TRAIT:
154+ //case T_TRAIT:
165155 // Find the classname
166-
156+
167157 while (($ t = $ tokens [++$ i ]) && is_array ($ t )) {
168158 if (T_STRING === $ t [0 ]) {
169159 $ class .= $ t [1 ];
@@ -173,16 +163,11 @@ private static function findClasses($path)
173163 }
174164
175165 $ classes [] = ltrim ($ namespace . $ class , '\\' );
176- /*if ($nbResults == 1) {
177- // Optim: if there is only one "class" keyword in the file, there is only one class, and we have it!
178- return $classes;
179- }*/
180166 break ;
181167 default :
182168 break ;
183169 }
184170 }
185-
186171
187172 return $ classes ;
188173 }
0 commit comments