Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move betterNodeFinder,valueResolver,phpDocInfoFactory dependencies from AbstractRector into rules #194

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpParser\Node\Expr\Ternary;
use PHPStan\Type\BooleanType;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -25,6 +26,7 @@ final class DowngradeJsonDecodeNullAssociativeArgRector extends AbstractRector
{
public function __construct(
private readonly ArgsAnalyzer $argsAnalyzer,
private readonly ValueResolver $valueResolver,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\DowngradePhp72\NodeAnalyzer\RegexFuncAnalyzer;
use Rector\DowngradePhp72\NodeManipulator\BitwiseFlagCleaner;
Expand All @@ -40,6 +41,7 @@ final class DowngradePregUnmatchedAsNullConstantRector extends AbstractRector
public function __construct(
private readonly BitwiseFlagCleaner $bitwiseFlagCleaner,
private readonly RegexFuncAnalyzer $regexFuncAnalyzer,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\Type\Type;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\DowngradePhp81\NodeAnalyzer\ArraySpreadAnalyzer;
use Rector\DowngradePhp81\NodeFactory\ArrayMergeFromArraySpreadFactory;
Expand All @@ -33,7 +34,8 @@ final class DowngradeArraySpreadRector extends AbstractScopeAwareRector
public function __construct(
private readonly ArrayMergeFromArraySpreadFactory $arrayMergeFromArraySpreadFactory,
private readonly ArraySpreadAnalyzer $arraySpreadAnalyzer,
private readonly AstResolver $astResolver
private readonly AstResolver $astResolver,
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\Expr\Variable;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Throw_;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Php72\NodeFactory\AnonymousFunctionFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -25,7 +26,8 @@
final class ArrowFunctionToAnonymousFunctionRector extends AbstractRector
{
public function __construct(
private readonly AnonymousFunctionFactory $anonymousFunctionFactory
private readonly AnonymousFunctionFactory $anonymousFunctionFactory,
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\Function_;
use PhpParser\Node\UnionType;
use PHPStan\Reflection\ClassReflection;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
use Rector\Core\Rector\AbstractRector;
Expand All @@ -34,7 +35,8 @@ final class DowngradeContravariantArgumentTypeRector extends AbstractRector
public function __construct(
private readonly PhpDocTypeChanger $phpDocTypeChanger,
private readonly ParamAnalyzer $paramAnalyzer,
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 @@ -19,6 +19,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -28,6 +29,11 @@
*/
final class DowngradeStripTagsCallWithArrayRector extends AbstractRector
{
public function __construct(
private readonly ValueResolver $valueResolver
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -23,6 +24,11 @@ final class DowngradeFreadFwriteFalsyToNegationRector extends AbstractRector
*/
private const FUNC_FREAD_FWRITE = ['fread', 'fwrite'];

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

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Property;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeManipulator\PropertyDecorator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -19,7 +20,8 @@
final class DowngradeTypedPropertyRector extends AbstractRector
{
public function __construct(
private readonly PropertyDecorator $propertyDecorator
private readonly PropertyDecorator $propertyDecorator,
private readonly ValueResolver $valueResolver
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
Expand Down Expand Up @@ -45,6 +46,7 @@ final class DowngradeAttributeToAnnotationRector extends AbstractRector implemen
public function __construct(
private readonly DoctrineAnnotationFactory $doctrineAnnotationFactory,
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 Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
Expand All @@ -36,6 +37,7 @@ public function __construct(
private readonly PhpDocTypeChanger $phpDocTypeChanger,
private readonly BetterStandardPrinter $betterStandardPrinter,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\NodeManipulator\BinaryOpManipulator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeAnalyzer\CoalesceAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -39,6 +40,7 @@ final class DowngradeThrowExprRector extends AbstractRector
public function __construct(
private readonly CoalesceAnalyzer $coalesceAnalyzer,
private readonly BinaryOpManipulator $binaryOpManipulator,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down Expand Up @@ -190,8 +192,8 @@ private function hasThrowInAssignExpr(Assign $assign): bool
*/
private function refactorReturn(Return_ $return): ?array
{
$throwExpr = $this->betterNodeFinder->findFirstInstanceOf($return, Throw_::class);
if (! $throwExpr instanceof Throw_) {
$throw = $this->betterNodeFinder->findFirstInstanceOf($return, Throw_::class);
if (! $throw instanceof Throw_) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\StringType;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -40,7 +41,8 @@
final class DowngradeArrayFilterNullableCallbackRector extends AbstractRector
{
public function __construct(
private readonly ArgsAnalyzer $argsAnalyzer
private readonly ArgsAnalyzer $argsAnalyzer,
private readonly ValueResolver $valueResolver
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeFactory\NamedVariableFactory;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand All @@ -31,6 +32,7 @@ final class DowngradeArbitraryExpressionsSupportRector extends AbstractRector
{
public function __construct(
private readonly NamedVariableFactory $namedVariableFactory,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\UnionType;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Rector\Php72\NodeFactory\AnonymousFunctionFactory;
Expand All @@ -42,7 +43,8 @@
final class DowngradeNewInInitializerRector extends AbstractRector
{
public function __construct(
private readonly AnonymousFunctionFactory $anonymousFunctionFactory
private readonly AnonymousFunctionFactory $anonymousFunctionFactory,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

Expand Down
Loading