Skip to content

Commit 6337a1b

Browse files
committed
tidy up
1 parent 6283097 commit 6337a1b

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

rules/Configs/Rector/Class_/ParameterBagToAutowireAttributeRector.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
use PhpParser\Node\Scalar\String_;
1212
use PhpParser\Node\Stmt\Class_;
1313
use PhpParser\Node\Stmt\ClassMethod;
14+
use PHPStan\Reflection\ReflectionProvider;
1415
use PHPStan\Type\ObjectType;
1516
use Rector\Rector\AbstractRector;
1617
use Rector\Symfony\Configs\NodeFactory\AutowiredParamFactory;
18+
use Rector\Symfony\Enum\SymfonyAttribute;
19+
use Rector\Symfony\Enum\SymfonyClass;
1720
use Rector\ValueObject\MethodName;
1821
use Rector\ValueObject\PhpVersionFeature;
1922
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
@@ -28,13 +31,9 @@
2831
*/
2932
final class ParameterBagToAutowireAttributeRector extends AbstractRector implements MinPhpVersionInterface
3033
{
31-
/**
32-
* @var string
33-
*/
34-
private const PARAMETER_BAG_CLASS = 'Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface';
35-
3634
public function __construct(
37-
private readonly AutowiredParamFactory $autowiredParamFactory
35+
private readonly AutowiredParamFactory $autowiredParamFactory,
36+
private readonly ReflectionProvider $reflectionProvider
3837
) {
3938
}
4039

@@ -85,6 +84,10 @@ public function getNodeTypes(): array
8584
*/
8685
public function refactor(Node $node): ?Class_
8786
{
87+
if (! $this->reflectionProvider->hasClass(SymfonyAttribute::AUTOWIRE)) {
88+
return null;
89+
}
90+
8891
if ($node->isAnonymous()) {
8992
return null;
9093
}
@@ -112,7 +115,7 @@ public function refactor(Node $node): ?Class_
112115
return null;
113116
}
114117

115-
if (! $this->isObjectType($node->var, new ObjectType(self::PARAMETER_BAG_CLASS))) {
118+
if (! $this->isObjectType($node->var, new ObjectType(SymfonyClass::PARAMETER_BAG_INTERFACE))) {
116119
return null;
117120
}
118121

@@ -191,6 +194,6 @@ private function isParameterBagParam(Param $param): bool
191194
return false;
192195
}
193196

194-
return $this->isName($param->type, self::PARAMETER_BAG_CLASS);
197+
return $this->isName($param->type, SymfonyClass::PARAMETER_BAG_INTERFACE);
195198
}
196199
}

src/Enum/SymfonyClass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ final class SymfonyClass
141141
*/
142142
public const PARAMETER_BAG = 'Symfony\Component\HttpFoundation\ParameterBag';
143143

144+
/**
145+
* @var string
146+
*/
147+
public const PARAMETER_BAG_INTERFACE = 'Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface';
148+
144149
/**
145150
* @var string
146151
*/

0 commit comments

Comments
 (0)