@@ -49,7 +49,23 @@ public function process(File $phpcsFile, $stackPtr)
49
49
$ exceptionString = 'Exception ' ;
50
50
$ customExceptionFound = false ;
51
51
foreach ($ tokens as $ key => $ token ) {
52
- if ($ token ['code ' ] === T_USE ) {
52
+ if ($ token ['code ' ] !== T_USE ) {
53
+ continue ;
54
+ }
55
+ $ endOfUse = $ phpcsFile ->findEndOfStatement ($ key );
56
+ $ useStatementValue = $ this ->getFullClassNameAndAlias ($ tokens , $ key , $ endOfUse );
57
+ // we safely consider use statement has alias will not be a direct exception class
58
+ if (!empty ($ useStatementValue ['alias ' ])) {
59
+ continue ;
60
+ }
61
+ if (substr ($ useStatementValue ['name ' ], 0 , strlen ($ exceptionString )) !== $ exceptionString
62
+ && substr ($ useStatementValue ['name ' ], -strlen ($ exceptionString )) === $ exceptionString
63
+ && $ useStatementValue ['name ' ] !== $ exceptionString
64
+ ) {
65
+ $ customExceptionFound = true ;
66
+ break ;
67
+ }
68
+ }
53
69
$ endOfUse = $ phpcsFile ->findEndOfStatement ($ key );
54
70
$ useStatementValue = $ this ->getFullClassNameAndAlias ($ tokens , $ key , $ endOfUse );
55
71
//we safely consider use statement has alias will not be a direct exception class
@@ -84,7 +100,7 @@ public function process(File $phpcsFile, $stackPtr)
84
100
* @param int $end
85
101
* @return array
86
102
*/
87
- private function getFullClassNameAndAlias ($ tokens , $ start , $ end )
103
+ private function getFullClassNameAndAlias ($ tokens , $ start , $ end ): array
88
104
{
89
105
$ fullName = $ alias = '' ;
90
106
$ foundAlias = false ;
0 commit comments