File tree Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Original file line number Diff line number Diff line change 4
4
5
5
namespace Rector \Core \NodeAnalyzer ;
6
6
7
- use PhpParser \Node ;
8
7
use PhpParser \Node \Stmt ;
9
8
use Rector \NodeTypeResolver \Node \AttributeKey ;
10
9
11
10
final class UnreachableStmtAnalyzer
12
11
{
13
- public function isStmtPHPStanUnreachable (Stmt $ stmt ): bool
12
+ public function isStmtPHPStanUnreachable (? Stmt $ stmt ): bool
14
13
{
14
+ if (! $ stmt instanceof Stmt) {
15
+ return false ;
16
+ }
17
+
15
18
if ($ stmt ->getAttribute (AttributeKey::IS_UNREACHABLE ) === true ) {
16
19
// here the scope is never available for next stmt so we have nothing to refresh
17
20
return true ;
18
21
}
19
22
20
- $ previousStmt = $ stmt ;
21
- while ($ previousStmt = $ previousStmt ->getAttribute (AttributeKey::PREVIOUS_NODE )) {
22
- if (! $ previousStmt instanceof Node) {
23
- break ;
24
- }
25
-
26
- if ($ previousStmt ->getAttribute (AttributeKey::IS_UNREACHABLE ) === true ) {
27
- return true ;
28
- }
29
- }
30
-
31
- return false ;
23
+ $ previousStmt = $ stmt ->getAttribute (AttributeKey::PREVIOUS_NODE );
24
+ return $ this ->isStmtPHPStanUnreachable ($ previousStmt );
32
25
}
33
26
}
You can’t perform that action at this time.
0 commit comments