Skip to content

Commit

Permalink
[DX] Make PhpDocInfoFactory explicitly required in Rector rule constr…
Browse files Browse the repository at this point in the history
…uctor, if needed (#5051)
  • Loading branch information
TomasVotruba committed Sep 20, 2023
1 parent 5ee831f commit 33fa626
Show file tree
Hide file tree
Showing 31 changed files with 200 additions and 21 deletions.
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,9 @@ parameters:
path: rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorReadonlyClassRector.php

- '#Fetching class constant class of deprecated class Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictConstructorReadonlyClassRector#'

# dev rule
- '#Class "Rector\\Utils\\Rector\\MoveAbstractRectorToChildrenRector" is missing @see annotation with test case class reference#'

# deprecated parent property
- '#Access to deprecated property \$phpDocInfoFactory of class Rector\\Core\\Rector\\AbstractRector#'
8 changes: 5 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenCollectorRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Collector\ParentClassCollector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
use Rector\Utils\Rector\MoveAbstractRectorToChildrenRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
Expand All @@ -33,11 +35,11 @@
PHPUnitSetList::PHPUNIT_100,
]);

// @todo collectors - just for testing purpose
// testing collectors
$rectorConfig->collector(ParentClassCollector::class);
$rectorConfig->rule(\Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenCollectorRector::class);
$rectorConfig->rule(FinalizeClassesWithoutChildrenCollectorRector::class);

$rectorConfig->rules([DeclareStrictTypesRector::class]);
$rectorConfig->rules([DeclareStrictTypesRector::class, MoveAbstractRectorToChildrenRector::class]);

$rectorConfig->paths([
__DIR__ . '/bin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\MixedType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\NodeAnalyzer\CallAnalyzer;
use Rector\Core\NodeAnalyzer\VariableAnalyzer;
Expand All @@ -30,7 +31,8 @@ final class SimplifyUselessVariableRector extends AbstractRector
public function __construct(
private readonly AssignAndBinaryMap $assignAndBinaryMap,
private readonly VariableAnalyzer $variableAnalyzer,
private readonly CallAnalyzer $callAnalyzer
private readonly CallAnalyzer $callAnalyzer,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
4 changes: 3 additions & 1 deletion rules/CodeQuality/Rector/If_/CombineIfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use Rector\BetterPhpDocParser\Comment\CommentsMerger;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -21,7 +22,8 @@
final class CombineIfRector extends AbstractRector
{
public function __construct(
private readonly CommentsMerger $commentsMerger
private readonly CommentsMerger $commentsMerger,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\CodingStyle\TypeAnalyzer\IterableTypeAnalyzer;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractRector;
Expand All @@ -34,7 +35,8 @@ public function __construct(
private readonly PropertyFetchAnalyzer $propertyFetchAnalyzer,
private readonly IterableTypeAnalyzer $iterableTypeAnalyzer,
private readonly VisibilityManipulator $visibilityManipulator,
private readonly ConstructorAssignDetector $constructorAssignDetector
private readonly ConstructorAssignDetector $constructorAssignDetector,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
2 changes: 2 additions & 0 deletions rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
Expand All @@ -32,6 +33,7 @@ final class RemoveAnnotationRector extends AbstractRector implements Configurabl
public function __construct(
private readonly PhpDocTagRemover $phpDocTagRemover,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Rector\AbstractRector;
Expand All @@ -29,6 +30,7 @@ public function __construct(
private readonly UnusedParameterResolver $unusedParameterResolver,
private readonly PhpDocTagRemover $phpDocTagRemover,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\ParamTagRemover;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -18,7 +19,8 @@
final class RemoveUselessParamTagRector extends AbstractRector
{
public function __construct(
private readonly ParamTagRemover $paramTagRemover
private readonly ParamTagRemover $paramTagRemover,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\ReturnTagRemover;
Expand All @@ -20,6 +21,7 @@ final class RemoveUselessReturnTagRector extends AbstractRector
public function __construct(
private readonly ReturnTagRemover $returnTagRemover,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
4 changes: 3 additions & 1 deletion rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt\Nop;
use PhpParser\NodeTraverser;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
Expand All @@ -27,7 +28,8 @@ final class RemoveDeadStmtRector extends AbstractRector
public function __construct(
private readonly LivingCodeManipulator $livingCodeManipulator,
private readonly PropertyFetchAnalyzer $propertyFetchAnalyzer,
private readonly ReflectionResolver $reflectionResolver
private readonly ReflectionResolver $reflectionResolver,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PhpParser\Node\Stmt\While_;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\NodeManipulator\StmtsManipulator;
Expand Down Expand Up @@ -55,6 +56,7 @@ final class RemoveNonExistingVarAnnotationRector extends AbstractRector
public function __construct(
private readonly StmtsManipulator $stmtsManipulator,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPStan\Analyser\Scope;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\DeadCode\NodeAnalyzer\PropertyWriteonlyAnalyzer;
Expand All @@ -28,6 +29,7 @@ final class RemoveUnusedPrivatePropertyRector extends AbstractScopeAwareRector
public function __construct(
private readonly PropertyFetchFinder $propertyFetchFinder,
private readonly PropertyWriteonlyAnalyzer $propertyWriteonlyAnalyzer,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
2 changes: 2 additions & 0 deletions rules/DeadCode/Rector/Property/RemoveUselessVarTagRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Stmt\Property;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -18,6 +19,7 @@ final class RemoveUselessVarTagRector extends AbstractRector
{
public function __construct(
private readonly VarTagRemover $varTagRemover,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\NodeAnalyzer\VariableAnalyzer;
use Rector\Core\Rector\AbstractRector;
Expand All @@ -26,7 +27,8 @@
final class ReturnEarlyIfVariableRector extends AbstractRector
{
public function __construct(
private readonly VariableAnalyzer $variableAnalyzer
private readonly VariableAnalyzer $variableAnalyzer,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Rector\AbstractRector;
use Rector\Naming\Guard\BreakingVariableRenameGuard;
Expand Down Expand Up @@ -42,7 +43,8 @@ public function __construct(
private readonly VarTagValueNodeRenamer $varTagValueNodeRenamer,
private readonly VariableAndCallAssignMatcher $variableAndCallAssignMatcher,
private readonly VariableRenamer $variableRenamer,
private readonly DocBlockUpdater $docBlockUpdater
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
2 changes: 2 additions & 0 deletions rules/Php80/Rector/Class_/AnnotationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
Expand Down Expand Up @@ -61,6 +62,7 @@ public function __construct(
private readonly UseImportsResolver $useImportsResolver,
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\TypeCombinator;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
use Rector\Core\Rector\AbstractRector;
Expand Down Expand Up @@ -67,7 +68,8 @@ public function __construct(
private readonly MakePropertyPromotionGuard $makePropertyPromotionGuard,
private readonly TypeComparator $typeComparator,
private readonly ReflectionResolver $reflectionResolver,
private readonly PropertyPromotionRenamer $propertyPromotionRenamer
private readonly PropertyPromotionRenamer $propertyPromotionRenamer,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
4 changes: 3 additions & 1 deletion rules/Php80/Rector/FunctionLike/MixedTypeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -34,7 +35,8 @@ final class MixedTypeRector extends AbstractRector implements MinPhpVersionInter
public function __construct(
private readonly ReflectionResolver $reflectionResolver,
private readonly ClassChildAnalyzer $classChildAnalyzer,
private readonly ParamTagRemover $paramTagRemover
private readonly ParamTagRemover $paramTagRemover,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
Expand Down Expand Up @@ -49,6 +50,7 @@ public function __construct(
private readonly NestedAttrGroupsFactory $nestedAttrGroupsFactory,
private readonly UseNodesToAddCollector $useNodesToAddCollector,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
2 changes: 2 additions & 0 deletions rules/Renaming/Rector/ClassMethod/RenameAnnotationRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Property;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
Expand All @@ -33,6 +34,7 @@ final class RenameAnnotationRector extends AbstractRector implements Configurabl
public function __construct(
private readonly DocBlockTagReplacer $docBlockTagReplacer,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand Down Expand Up @@ -46,7 +47,8 @@ final class AddParamTypeBasedOnPHPUnitDataProviderRector extends AbstractRector

public function __construct(
private readonly TypeFactory $typeFactory,
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
private readonly TestsNodeAnalyzer $testsNodeAnalyzer,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\PhpVersion;
Expand All @@ -40,7 +41,8 @@ final class ReturnTypeFromStrictNewArrayRector extends AbstractScopeAwareRector
public function __construct(
private readonly PhpDocTypeChanger $phpDocTypeChanger,
private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard,
private readonly ReturnTypeInferer $returnTypeInferer
private readonly ReturnTypeInferer $returnTypeInferer,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Rector\AbstractRector;
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -33,6 +34,7 @@ final class StrictStringParamConcatRector extends AbstractRector
{
public function __construct(
private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
) {
}

Expand Down

2 comments on commit 33fa626

@staabm
Copy link
Contributor

@staabm staabm commented on 33fa626 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/rectorphp/rector-src/actions/runs/6259982317/job/16997104022?pr=5026

PHP Fatal error:  Cannot redeclare non-readonly property Rector\Core\Rector\AbstractRector::$phpDocInfoFactory as readonly Rector\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector::$phpDocInfoFactory in /home/runner/work/rector-src/rector-src/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php on line 33

related?

@TomasVotruba
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might help: rectorphp/rector-downgrade-php@2b2a7cd

Could you rebase + composer update?

Please sign in to comment.