@@ -106,44 +106,30 @@ public function process(File $phpcsFile, $stackPtr)
106
106
107
107
$ nextToken = $ phpcsFile ->findNext (Tokens::$ emptyTokens , ($ currPos + 1 ), null , true );
108
108
if ($ tokens [$ nextToken ]['code ' ] === T_NEW
109
- || $ tokens [$ nextToken ]['code ' ] === T_NS_SEPARATOR
110
- || $ tokens [$ nextToken ]['code ' ] === T_STRING
109
+ || isset (Tokens::$ nameTokens [$ tokens [$ nextToken ]['code ' ]]) === true
111
110
) {
112
111
if ($ tokens [$ nextToken ]['code ' ] === T_NEW ) {
113
112
$ currException = $ phpcsFile ->findNext (
114
- [
115
- T_NS_SEPARATOR ,
116
- T_STRING ,
117
- ],
118
- $ currPos ,
113
+ Tokens::$ emptyTokens ,
114
+ ($ nextToken + 1 ),
119
115
$ stackPtrEnd ,
120
- false ,
121
- null ,
122
116
true
123
117
);
124
118
} else {
125
119
$ currException = $ nextToken ;
126
120
}
127
121
128
- if ($ currException !== false ) {
129
- $ endException = $ phpcsFile ->findNext (
130
- [
131
- T_NS_SEPARATOR ,
132
- T_STRING ,
133
- ],
134
- ($ currException + 1 ),
135
- $ stackPtrEnd ,
136
- true ,
137
- null ,
138
- true
139
- );
140
-
141
- if ($ endException === false ) {
142
- $ thrownExceptions [] = $ tokens [$ currException ]['content ' ];
122
+ if ($ currException !== false
123
+ && isset (Tokens::$ nameTokens [$ tokens [$ currException ]['code ' ]]) === true
124
+ ) {
125
+ if ($ tokens [$ currException ]['code ' ] === T_NAME_RELATIVE ) {
126
+ // Strip the `namespace\` prefix off the exception name
127
+ // to prevent confusing the name comparison.
128
+ $ thrownExceptions [] = substr ($ tokens [$ currException ]['content ' ], 10 );
143
129
} else {
144
- $ thrownExceptions [] = $ phpcsFile -> getTokensAsString ( $ currException, ( $ endException - $ currException )) ;
130
+ $ thrownExceptions [] = $ tokens [ $ currException][ ' content ' ] ;
145
131
}
146
- }//end if
132
+ }
147
133
} else if ($ tokens [$ nextToken ]['code ' ] === T_VARIABLE ) {
148
134
// Find the nearest catch block in this scope and, if the caught var
149
135
// matches our re-thrown var, use the exception types being caught as
0 commit comments