Skip to content

Commit 7495965

Browse files
committed
[experiment] skip beforeTraverse() and afterTraverse() as never used
1 parent 9305ed0 commit 7495965

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ public function refactor(Node $node): ?Node
6969
return null;
7070
}
7171

72+
<<<<<<< HEAD
7273
$oldTokens = $this->getFile()
7374
->getOldTokens();
75+
=======
76+
$oldTokens = $this->file->getOldTokens();
77+
78+
>>>>>>> 7556383dcf ([experiment] skip beforeTraverse() and afterTraverse() as never used)
7479
if ($this->isIfConditionFollowedByOpeningCurlyBracket($node, $oldTokens)) {
7580
return null;
7681
}

‎rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ private function shouldSkip(ArrayDimFetch $arrayDimFetch, Node $scopeNode): bool
179179
if ($scope->isInExpressionAssign($arrayDimFetch)) {
180180
return true;
181181
}
182+
<<<<<<< HEAD
182183

183184
if ($arrayDimFetch->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === true) {
184185
return true;
@@ -188,6 +189,8 @@ private function shouldSkip(ArrayDimFetch $arrayDimFetch, Node $scopeNode): bool
188189
return true;
189190
}
190191

192+
=======
193+
>>>>>>> ce85ccbfcc (fixup! [experiment] skip beforeTraverse() and afterTraverse() as never used)
191194
return (bool) $arrayDimFetch->getAttribute(AttributeKey::IS_UNSET_VAR);
192195
}
193196
}

‎src/PostRector/Rector/AbstractPostRector.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected function addRectorClassWithLine(Node $node): void
4141
Assert::isInstanceOf($this->file, File::class);
4242

4343
$rectorWithLineChange = new RectorWithLineChange(static::class, $node->getStartLine());
44-
$this->file->addRectorClassWithLine($rectorWithLineChange);
44+
$this->getFile()
45+
->addRectorClassWithLine($rectorWithLineChange);
4546
}
4647
}

‎src/Rector/AbstractRector.php‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
use Rector\Skipper\Skipper\Skipper;
3636
use Rector\ValueObject\Application\File;
3737

38+
/**
39+
* @property-read File $file @deprecated Use $this->getFile() instead
40+
*/
3841
abstract class AbstractRector extends NodeVisitorAbstract implements RectorInterface
3942
{
4043
private const string EMPTY_NODE_ARRAY_MESSAGE = <<<CODE_SAMPLE
@@ -57,11 +60,14 @@ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInter
5760

5861
protected NodeComparator $nodeComparator;
5962

63+
<<<<<<< HEAD
6064
/**
6165
* @deprecated Use getFile() instead.
6266
*/
6367
protected File $file;
6468

69+
=======
70+
>>>>>>> 7556383dcf ([experiment] skip beforeTraverse() and afterTraverse() as never used)
6571
protected Skipper $skipper;
6672

6773
private ChangedNodeScopeRefresher $changedNodeScopeRefresher;
@@ -74,6 +80,16 @@ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInter
7480

7581
private CreatedByRuleDecorator $createdByRuleDecorator;
7682

83+
public function __get(string $name): mixed
84+
{
85+
if ($name === 'file') {
86+
return $this->getFile();
87+
}
88+
89+
// fallback to default behavior
90+
return $this->{$name};
91+
}
92+
7793
public function autowire(
7894
NodeNameResolver $nodeNameResolver,
7995
NodeTypeResolver $nodeTypeResolver,
@@ -100,23 +116,12 @@ public function autowire(
100116

101117
/**
102118
* @final Avoid override to prevent unintended side-effects. Use enterNode() or @see \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface instead.
103-
*
104119
* @internal
105120
*
106121
* @return Node[]|null
107122
*/
108123
public function beforeTraverse(array $nodes): ?array
109124
{
110-
// workaround for file around refactor()
111-
$file = $this->currentFileProvider->getFile();
112-
if (! $file instanceof File) {
113-
throw new ShouldNotHappenException(
114-
'File object is missing. Make sure you call $this->currentFileProvider->setFile(...) before traversing.'
115-
);
116-
}
117-
118-
$this->file = $file;
119-
120125
return null;
121126
}
122127

0 commit comments

Comments
 (0)