@@ -98,22 +98,13 @@ private static function findClasses($path)
98
98
{
99
99
$ contents = file_get_contents ($ path );
100
100
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
-
110
101
// Let's trim the content after the last "class" keyword line.
111
102
$ classKeywordPos = strrpos ($ contents , 'class ' );
112
103
if ($ classKeywordPos === false ) {
113
104
return array ();
114
105
}
115
106
//$classKeywordPos = $results[0][count($results[0])-1][1];
116
-
107
+
117
108
// Jump 2 newlines after the last class keyword.
118
109
if (strlen ($ contents ) > $ classKeywordPos +6 ) {
119
110
$ newLinePos = strpos ($ contents , "\n" , $ classKeywordPos +6 );
@@ -124,21 +115,20 @@ private static function findClasses($path)
124
115
}
125
116
}
126
117
}
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
129
120
// comment.
130
121
$ currentErrorReporting = error_reporting (E_ALL & ~E_COMPILE_WARNING );
131
122
$ tokens = token_get_all ($ contents );
132
123
error_reporting ($ currentErrorReporting );
133
124
} catch (\Exception $ e ) {
134
125
throw new \RuntimeException ('Could not scan for classes inside ' .$ path .": \n" .$ e ->getMessage (), 0 , $ e );
135
126
}
136
- $ T_TRAIT = version_compare (PHP_VERSION , '5.4 ' , '< ' ) ? -1 : T_TRAIT ;
137
127
138
128
$ classes = array ();
139
129
140
130
$ namespace = '' ;
141
-
131
+
142
132
for ($ i = 0 , $ max = count ($ tokens ); $ i < $ max ; $ i ++) {
143
133
$ token = $ tokens [$ i ];
144
134
@@ -153,17 +143,17 @@ private static function findClasses($path)
153
143
$ namespace = '' ;
154
144
// If there is a namespace, extract it
155
145
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 ))) {
157
147
$ namespace .= $ t [1 ];
158
148
}
159
149
}
160
150
$ namespace .= '\\' ;
161
151
break ;
162
152
case T_CLASS :
163
153
//case T_INTERFACE:
164
- //case $ T_TRAIT:
154
+ //case T_TRAIT:
165
155
// Find the classname
166
-
156
+
167
157
while (($ t = $ tokens [++$ i ]) && is_array ($ t )) {
168
158
if (T_STRING === $ t [0 ]) {
169
159
$ class .= $ t [1 ];
@@ -173,16 +163,11 @@ private static function findClasses($path)
173
163
}
174
164
175
165
$ 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
- }*/
180
166
break ;
181
167
default :
182
168
break ;
183
169
}
184
170
}
185
-
186
171
187
172
return $ classes ;
188
173
}
0 commit comments