Skip to content

Commit 49d366d

Browse files
committed
[config] add registerDecoratingNodeVisitor()
1 parent 777a06f commit 49d366d

File tree

11 files changed

+47
-11
lines changed

11 files changed

+47
-11
lines changed

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ parameters:
265265
# see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110
266266
- '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#'
267267

268+
# BC layer on Rector deprecation
269+
-
270+
path: src/Configuration/RectorConfigBuilder.php
271+
identifier: classConstant.deprecatedInterface
272+
268273
# allowed internally only
269274
-
270275
message: '#Fetching (deprecated )?class constant (.*?) of (deprecated )?class (Rector\\Set\\ValueObject\\DowngradeLevelSetList|Rector\\Symfony\\Set\\(.*?))#'

src/Configuration/RectorConfigBuilder.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\Configuration;
66

7+
use PhpParser\NodeVisitor;
78
use Rector\Bridge\SetProviderCollector;
89
use Rector\Bridge\SetRectorsResolver;
910
use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
@@ -18,11 +19,13 @@
1819
use Rector\Configuration\Levels\LevelRulesResolver;
1920
use Rector\Configuration\Parameter\SimpleParameterProvider;
2021
use Rector\Console\Notifier;
22+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
2123
use Rector\Contract\Rector\ConfigurableRectorInterface;
2224
use Rector\Contract\Rector\RectorInterface;
2325
use Rector\Doctrine\Set\DoctrineSetList;
2426
use Rector\Enum\Config\Defaults;
2527
use Rector\Exception\Configuration\InvalidConfigurationException;
28+
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
2629
use Rector\Php\PhpVersionResolver\ComposerJsonPhpVersionResolver;
2730
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
2831
use Rector\Php80\ValueObject\AnnotationToAttribute;
@@ -1217,11 +1220,33 @@ public function withTreatClassesAsFinal(bool $isTreatClassesAsFinal = true): sel
12171220

12181221
public function registerService(string $className, ?string $alias = null, ?string $tag = null): self
12191222
{
1223+
// BC layer since 2.2.9
1224+
if ($tag === ScopeResolverNodeVisitorInterface::class) {
1225+
$tag = DecoratingNodeVisitorInterface::class;
1226+
}
1227+
12201228
$this->registerServices[] = new RegisteredService($className, $alias, $tag);
12211229

12221230
return $this;
12231231
}
12241232

1233+
/**
1234+
* DX helper
1235+
* @see https://getrector.com/documentation/creating-a-node-visitor
1236+
*/
1237+
public function registerDecoratingNodeVisitor(string $decoratingNodeVisitorClass): self
1238+
{
1239+
Assert::isAOf($decoratingNodeVisitorClass, NodeVisitor::class);
1240+
1241+
$this->registerServices[] = new RegisteredService(
1242+
$decoratingNodeVisitorClass,
1243+
null,
1244+
DecoratingNodeVisitorInterface::class
1245+
);
1246+
1247+
return $this;
1248+
}
1249+
12251250
public function withDowngradeSets(
12261251
bool $php84 = false,
12271252
bool $php83 = false,

src/NodeTypeResolver/PHPStan/Scope/Contract/NodeVisitor/ScopeResolverNodeVisitorInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
namespace Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor;
66

77
use PhpParser\NodeVisitor;
8-
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
98

109
/**
11-
* @deprecated Use
12-
* @see DecoratingNodeVisitorInterface instead
10+
* @deprecated Since 2.2.9. Use \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface instead
1311
*/
1412
interface ScopeResolverNodeVisitorInterface extends NodeVisitor
1513
{

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ArgNodeVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
use PhpParser\Node\Expr\FuncCall;
1212
use PhpParser\Node\Name;
1313
use PhpParser\NodeVisitorAbstract;
14+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
1415
use Rector\NodeTypeResolver\Node\AttributeKey;
1516

16-
final class ArgNodeVisitor extends NodeVisitorAbstract implements \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface
17+
final class ArgNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
1718
{
1819
public function enterNode(Node $node): ?Node
1920
{

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
use PhpParser\Node\Expr\AssignRef;
1212
use PhpParser\Node\Expr\List_;
1313
use PhpParser\NodeVisitorAbstract;
14+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
1415
use Rector\NodeTypeResolver\Node\AttributeKey;
1516

1617
/**
1718
* Inspired by https://github.com/phpstan/phpstan-src/blob/1.7.x/src/Parser/NewAssignedToPropertyVisitor.php
1819
*/
19-
final class AssignedToNodeVisitor extends NodeVisitorAbstract implements \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface
20+
final class AssignedToNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
2021
{
2122
public function enterNode(Node $node): ?Node
2223
{

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefReturnNodeVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
use PhpParser\Node\Stmt\Return_;
1111
use PhpParser\NodeVisitor;
1212
use PhpParser\NodeVisitorAbstract;
13+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
1314
use Rector\NodeTypeResolver\Node\AttributeKey;
1415
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
1516

16-
final class ByRefReturnNodeVisitor extends NodeVisitorAbstract implements \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface
17+
final class ByRefReturnNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
1718
{
1819
public function __construct(
1920
private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefVariableNodeVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
use PhpParser\Node\Expr\Variable;
1212
use PhpParser\Node\FunctionLike;
1313
use PhpParser\NodeVisitorAbstract;
14+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
1415
use Rector\NodeTypeResolver\Node\AttributeKey;
1516
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
1617

17-
final class ByRefVariableNodeVisitor extends NodeVisitorAbstract implements \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface
18+
final class ByRefVariableNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
1819
{
1920
public function __construct(
2021
private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
use PhpParser\Node\Stmt\While_;
3535
use PhpParser\NodeVisitor;
3636
use PhpParser\NodeVisitorAbstract;
37+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
3738
use Rector\NodeTypeResolver\Node\AttributeKey;
3839
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
3940

40-
final class ContextNodeVisitor extends NodeVisitorAbstract implements \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface
41+
final class ContextNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
4142
{
4243
public function __construct(
4344
private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/GlobalVariableNodeVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
use PhpParser\Node\Stmt\Global_;
1313
use PhpParser\NodeVisitor;
1414
use PhpParser\NodeVisitorAbstract;
15+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
1516
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1617
use Rector\NodeTypeResolver\Node\AttributeKey;
1718
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
1819

19-
final class GlobalVariableNodeVisitor extends NodeVisitorAbstract implements \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface
20+
final class GlobalVariableNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
2021
{
2122
public function __construct(
2223
private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/NameNodeVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
use PhpParser\Node\Expr\StaticCall;
1212
use PhpParser\Node\Name;
1313
use PhpParser\NodeVisitorAbstract;
14+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
1415
use Rector\NodeTypeResolver\Node\AttributeKey;
1516

16-
final class NameNodeVisitor extends NodeVisitorAbstract implements \Rector\Contract\PhpParser\DecoratingNodeVisitorInterface
17+
final class NameNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
1718
{
1819
public function enterNode(Node $node): ?Node
1920
{

0 commit comments

Comments
 (0)