@@ -71,6 +71,70 @@ private function tline($token) {
71
71
throw new Exception ('Scalar tokens are not yet precalculated ' );
72
72
}
73
73
74
+ private function tname (array $ tokens , $ idx ) {
75
+ $ tconst = $ this ->tconst ($ tokens [$ idx ]);
76
+
77
+ if ($ tconst === T_REQUIRE || $ tconst === T_REQUIRE_ONCE || $ tconst === T_INCLUDE || $ tconst === T_INCLUDE_ONCE ) {
78
+ if ($ this ->tconst (tokens[$ idx +2 ]) === T_CONSTANT_ENCAPSED_STRING ) {
79
+ return trim ($ tokens [$ idx +2 ], "' \"" );
80
+ }
81
+ return null ;
82
+ }
83
+
84
+ if ($ tconst === T_FUNCTION ) {
85
+ for ($ i = $ idx + 1 ; $ i < count ($ tokens ); $ i ++) {
86
+ $ token = $ tokens [$ i ];
87
+ $ tconst = $ this ->tconst ($ token );
88
+ $ tclass = $ this ->tclass ($ token );
89
+
90
+ if ($ tconst === T_STRING ) {
91
+ $ name = (string )$ token ;
92
+ break ;
93
+ } elseif ($ tconst === T_STRING && $ tclass === 'PHP_Token_AMPERSAND ' && $ this ->tconst ($ tokens [$ i +1 ]) === T_STRING ) {
94
+ $ name = (string )$ tokens [$ i +1 ];
95
+ break ;
96
+ } elseif ($ tclass === 'PHP_Token_OPEN_BRACKET ' ) {
97
+ $ name = 'anonymous function ' ;
98
+ break ;
99
+ }
100
+ }
101
+
102
+ if ($ name != 'anonymous function ' ) {
103
+ for ($ i = $ idx ; $ i ; --$ i ) {
104
+ $ tconst = $ this ->tconst ($ tokens [$ i ]);
105
+ if ($ tconst === T_NAMESPACE ) {
106
+ $ name = $ this ->tname ($ tokens , $ i ) . '\\' . $ name ;
107
+ break ;
108
+ }
109
+
110
+ if ($ tconst === T_INTERFACE ) {
111
+ break ;
112
+ }
113
+ }
114
+ }
115
+
116
+ return $ name ;
117
+ }
118
+
119
+ if ($ tconst === T_CLASS || $ tconst === T_TRAIT ) {
120
+ return (string ) $ tokens [$ idx + 2 ];
121
+ }
122
+
123
+ if ($ tconst === T_NAMESPACE ) {
124
+ $ namespace = (string )$ tokens [$ idx +2 ];
125
+
126
+ for ($ i = $ idx + 3 ;; $ i += 2 ) {
127
+ if (isset ($ tokens [$ i ]) && $ this ->tconst ($ tokens [$ i ]) === T_NS_SEPARATOR ) {
128
+ $ namespace .= '\\' . $ tokens [$ i +1 ];
129
+ } else {
130
+ break ;
131
+ }
132
+ }
133
+
134
+ return $ namespace ;
135
+ }
136
+ }
137
+
74
138
/**
75
139
* @return string
76
140
*/
@@ -216,18 +280,18 @@ public function tokenize() {
216
280
);
217
281
218
282
if ($ this ->tconst ($ token ) === T_CLASS ) {
219
- $ class = ( string ) $ tokens[ $ i + 2 ] ;
283
+ $ class = $ this -> tname ( $ tokens, $ i + 2 ) ;
220
284
$ classEndLine = $ token ->getEndLine ();
221
285
$ this ->classes [$ class ] = $ tmp ;
222
286
} else {
223
- $ trait = ( string ) $ tokens[ $ i + 2 ] ;
287
+ $ trait = $ this -> tname ( $ tokens, $ i + 2 ) ;
224
288
$ traitEndLine = $ token ->getEndLine ();
225
289
$ this ->traits [$ trait ] = $ tmp ;
226
290
}
227
291
break ;
228
292
229
293
case 'PHP_Token_FUNCTION ' :
230
- $ name = $ token -> getName ( );
294
+ $ name = $ this -> tname ( $ tokens , $ idx );
231
295
$ tmp = array (
232
296
'docblock ' => $ token ->getDocblock (),
233
297
'keywords ' => $ this ->getKeywords ($ tokens , $ i ),
0 commit comments