Skip to content

Commit

Permalink
[DX] Make ValueResolver explicitly required in Rector rules construct…
Browse files Browse the repository at this point in the history
…or if needed (#5053)
  • Loading branch information
TomasVotruba committed Sep 20, 2023
1 parent 23d4292 commit e698133
Show file tree
Hide file tree
Showing 36 changed files with 106 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Foreach_;
use PHPStan\Type\ObjectType;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -22,7 +23,8 @@
final class UnusedForeachValueToArrayKeysRector extends AbstractRector
{
public function __construct(
private readonly ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer
private readonly ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -28,7 +29,8 @@ final class SimplifyIfElseToTernaryRector extends AbstractRector
private const LINE_LENGTH_LIMIT = 120;

public function __construct(
private readonly BetterStandardPrinter $betterStandardPrinter
private readonly BetterStandardPrinter $betterStandardPrinter,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
Expand All @@ -20,7 +21,8 @@
final class DataProviderArrayItemsNewlinedRector extends AbstractRector
{
public function __construct(
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
private readonly TestsNodeAnalyzer $testsNodeAnalyzer,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand All @@ -27,6 +28,11 @@
*/
final class FuncGetArgsToVariadicParamRector extends AbstractRector implements MinPhpVersionInterface
{
public function __construct(
private readonly BetterNodeFinder $betterNodeFinder
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Refactor func_get_args() in to a variadic param', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\CodingStyle\TypeAnalyzer\IterableTypeAnalyzer;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
Expand All @@ -38,7 +39,8 @@ public function __construct(
private readonly VisibilityManipulator $visibilityManipulator,
private readonly ConstructorAssignDetector $constructorAssignDetector,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly ValueResolver $valueResolver
private readonly ValueResolver $valueResolver,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
2 changes: 2 additions & 0 deletions rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Namespace_;
use PHPStan\Analyser\Scope;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
Expand All @@ -30,6 +31,7 @@ final class RemoveDoubleAssignRector extends AbstractScopeAwareRector
{
public function __construct(
private readonly SideEffectNodeDetector $sideEffectNodeDetector,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPStan\Analyser\Scope;
use Rector\Core\NodeAnalyzer\VariableAnalyzer;
use Rector\Core\Php\ReservedKeywordAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand All @@ -32,7 +33,8 @@ final class RemoveUnusedVariableAssignRector extends AbstractScopeAwareRector
public function __construct(
private readonly ReservedKeywordAnalyzer $reservedKeywordAnalyzer,
private readonly SideEffectNodeDetector $sideEffectNodeDetector,
private readonly VariableAnalyzer $variableAnalyzer
private readonly VariableAnalyzer $variableAnalyzer,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\NodeCollector\UnusedParameterResolver;
use Rector\DeadCode\NodeManipulator\VariadicFunctionLikeDetector;
Expand All @@ -31,6 +32,7 @@ public function __construct(
private readonly PhpDocTagRemover $phpDocTagRemover,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\MethodName;
Expand All @@ -25,7 +26,8 @@ final class RemoveUnusedPrivateMethodRector extends AbstractScopeAwareRector
{
public function __construct(
private readonly IsClassMethodUsedAnalyzer $isClassMethodUsedAnalyzer,
private readonly ReflectionResolver $reflectionResolver
private readonly ReflectionResolver $reflectionResolver,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\TraitUse;
use PHPStan\Analyser\Scope;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\MethodName;
Expand All @@ -30,6 +31,7 @@ public function __construct(
private readonly PropertyFetchFinder $propertyFetchFinder,
private readonly VisibilityManipulator $visibilityManipulator,
private readonly PropertyWriteonlyAnalyzer $propertyWriteonlyAnalyzer,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down
4 changes: 3 additions & 1 deletion rules/DeadCode/Rector/For_/RemoveDeadIfForeachForRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\If_;
use PhpParser\NodeTraverser;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\EarlyReturn\NodeTransformer\ConditionInverter;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -24,7 +25,8 @@
final class RemoveDeadIfForeachForRector extends AbstractRector
{
public function __construct(
private readonly ConditionInverter $conditionInverter
private readonly ConditionInverter $conditionInverter,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt\Foreach_;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -16,6 +17,11 @@
*/
final class RemoveUnusedForeachKeyRector extends AbstractRector
{
public function __construct(
private readonly BetterNodeFinder $betterNodeFinder
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Remove unused key in foreach', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\Constant\ConstantBooleanType;
use Rector\Core\NodeAnalyzer\ExprAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -29,7 +30,8 @@ final class RemoveAlwaysTrueIfConditionRector extends AbstractRector
{
public function __construct(
private readonly ReflectionResolver $reflectionResolver,
private readonly ExprAnalyzer $exprAnalyzer
private readonly ExprAnalyzer $exprAnalyzer,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\NodeManipulator\StmtsManipulator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -59,6 +60,7 @@ public function __construct(
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly ValueResolver $valueResolver,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Stmt\Return_;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\NodeManipulator\IfManipulator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\EarlyReturn\ValueObject\BareSingleAssignIf;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -25,7 +26,8 @@
final class PreparedValueToEarlyReturnRector extends AbstractRector
{
public function __construct(
private readonly IfManipulator $ifManipulator
private readonly IfManipulator $ifManipulator,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Naming\Guard\BreakingVariableRenameGuard;
use Rector\Naming\Naming\ExpectedNameResolver;
Expand All @@ -24,7 +25,8 @@ final class RenameVariableToMatchNewTypeRector extends AbstractRector
public function __construct(
private readonly BreakingVariableRenameGuard $breakingVariableRenameGuard,
private readonly ExpectedNameResolver $expectedNameResolver,
private readonly VariableRenamer $variableRenamer
private readonly VariableRenamer $variableRenamer,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\NodeManipulator\StmtsManipulator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Naming\ExpectedNameResolver\InflectorSingularResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -23,7 +24,8 @@ final class RenameForeachValueVariableToMatchExprVariableRector extends Abstract
public function __construct(
private readonly InflectorSingularResolver $inflectorSingularResolver,
private readonly PropertyFetchAnalyzer $propertyFetchAnalyzer,
private readonly StmtsManipulator $stmtsManipulator
private readonly StmtsManipulator $stmtsManipulator,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
4 changes: 3 additions & 1 deletion rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt\Expression;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand Down Expand Up @@ -46,7 +47,8 @@ final class ArrayKeyFirstLastRector extends AbstractRector implements MinPhpVers
];

public function __construct(
private readonly ReflectionProvider $reflectionProvider
private readonly ReflectionProvider $reflectionProvider,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
4 changes: 3 additions & 1 deletion rules/Php73/Rector/FuncCall/JsonThrowOnErrorRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\LNumber;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -29,7 +30,8 @@ final class JsonThrowOnErrorRector extends AbstractRector implements MinPhpVersi
private bool $hasChanged = false;

public function __construct(
private readonly ValueResolver $valueResolver
private readonly ValueResolver $valueResolver,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Stmt\TryCatch;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\NodeManipulator\StmtsManipulator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand All @@ -23,7 +24,8 @@
final class RemoveUnusedVariableInCatchRector extends AbstractRector implements MinPhpVersionInterface
{
public function __construct(
private readonly StmtsManipulator $stmtsManipulator
private readonly StmtsManipulator $stmtsManipulator,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\MethodReflection;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
Expand All @@ -40,6 +41,7 @@ public function __construct(
private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard,
private readonly AstResolver $astResolver,
private readonly BetterStandardPrinter $betterStandardPrinter,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down
4 changes: 3 additions & 1 deletion rules/Php80/Rector/Class_/StringableForToStringRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -38,7 +39,8 @@ final class StringableForToStringRector extends AbstractRector implements MinPhp
public function __construct(
private readonly FamilyRelationsAnalyzer $familyRelationsAnalyzer,
private readonly ReturnTypeInferer $returnTypeInferer,
private readonly ClassAnalyzer $classAnalyzer
private readonly ClassAnalyzer $classAnalyzer,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Loading

0 comments on commit e698133

Please sign in to comment.