@@ -50,10 +50,12 @@ private static function findClassOrTraitOrInterface(string $path): ?string
50
50
$ tokens = \token_get_all (\file_get_contents ($ path ));
51
51
52
52
foreach ($ tokens as $ key => $ token ) {
53
- if (self ::tokenIsNamespace ($ token )) {
54
- $ namespace = self ::getNamespace ($ key + 2 , $ tokens );
55
- } elseif (self ::tokenIsClassOrTraitOrInterface ($ token )) {
56
- return \ltrim ($ namespace . '\\' . self ::getClass ($ key + 2 , $ tokens ), '\\' );
53
+ if (\is_array ($ token )) {
54
+ if (self ::tokenIsNamespace ($ token )) {
55
+ $ namespace = self ::getNamespace ($ key + 2 , $ tokens );
56
+ } elseif (self ::tokenIsClassOrTraitOrInterface ($ token )) {
57
+ return \ltrim ($ namespace . '\\' . self ::getClass ($ key + 2 , $ tokens ), '\\' );
58
+ }
57
59
}
58
60
}
59
61
@@ -68,7 +70,7 @@ private static function findClassOrTraitOrInterface(string $path): ?string
68
70
*
69
71
* @return null|string
70
72
*/
71
- private static function getNamespace ($ key , array $ tokens ): ?string
73
+ private static function getNamespace (int $ key , array $ tokens ): ?string
72
74
{
73
75
$ namespace = null ;
74
76
$ tokenCount = \count ($ tokens );
@@ -123,13 +125,13 @@ private static function getClass($key, array $tokens): ?string
123
125
/**
124
126
* Determine if the given token is a namespace keyword.
125
127
*
126
- * @param array|string $token
128
+ * @param array $token
127
129
*
128
130
* @return bool
129
131
*/
130
- private static function tokenIsNamespace ($ token ): bool
132
+ private static function tokenIsNamespace (array $ token ): bool
131
133
{
132
- return \is_array ( $ token ) && $ token [0 ] === T_NAMESPACE ;
134
+ return $ token [0 ] === T_NAMESPACE ;
133
135
}
134
136
135
137
/**
@@ -147,13 +149,13 @@ private static function isPartOfClass($token): bool
147
149
/**
148
150
* Determine if the given token is a class or interface keyword.
149
151
*
150
- * @param array|string $token
152
+ * @param array $token
151
153
*
152
154
* @return bool
153
155
*/
154
- private static function tokenIsClassOrTraitOrInterface ($ token ): bool
156
+ private static function tokenIsClassOrTraitOrInterface (array $ token ): bool
155
157
{
156
- return \is_array ( $ token) && ( $ token [0 ] === T_CLASS || $ token [0 ] === T_INTERFACE || $ token [0 ] === T_TRAIT ) ;
158
+ return $ token [0 ] === T_CLASS || $ token [0 ] === T_INTERFACE || $ token [0 ] === T_TRAIT ;
157
159
}
158
160
159
161
/**
0 commit comments