File tree Expand file tree Collapse file tree
rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector
src/NodeTypeResolver/PHPStan/Scope Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DeadCode \Rector \ClassMethod \RemoveUnusedPrivateMethodRector \Fixture ;
4+
5+ use Illuminate \Database \Eloquent \Builder ;
6+ use Illuminate \Database \Eloquent \Model ;
7+ use Illuminate \Database \Eloquent \Relations \BelongsTo ;
8+ use Rector \Tests \DeadCode \Rector \ClassMethod \RemoveUnusedPrivateMethodRector \Source \RecursiveTrait ;
9+
10+ /**
11+ * @method static Builder<static>|BaseModel query()
12+ */
13+ class BaseModel extends Model {
14+ use RecursiveTrait;
15+
16+ public function parent (): BelongsTo {
17+ return $ this ->belongsTo (self ::class);
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \DeadCode \Rector \ClassMethod \RemoveUnusedPrivateMethodRector \Source ;
6+
7+ trait RecursiveTrait {
8+ public function getRecursive (): object {
9+ return new class () {
10+ use RecursiveTrait;
11+ };
12+ }
13+ }
Original file line number Diff line number Diff line change @@ -477,6 +477,14 @@ private function nodeScopeResolverProcessNodes(
477477 // in the middle of process
478478 // fallback to fill by found scope
479479 RectorNodeScopeResolver::processNodes ($ stmts , $ mutatingScope );
480+ } catch (Error $ error ) {
481+ if (! str_contains ($ error ->getMessage (), 'Infinite recursion? ' )) {
482+ throw $ error ;
483+ }
484+
485+ // handle stack overflow from recursive structures (e.g. self-referencing traits)
486+ // fallback to fill by found scope
487+ RectorNodeScopeResolver::processNodes ($ stmts , $ mutatingScope );
480488 }
481489 }
482490
You can’t perform that action at this time.
0 commit comments