diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md
index 59040604c2f..41422ab8a99 100644
--- a/build/target-repository/docs/rector_rules_overview.md
+++ b/build/target-repository/docs/rector_rules_overview.md
@@ -1,4 +1,4 @@
-# 383 Rules Overview
+# 377 Rules Overview
@@ -12,7 +12,7 @@
- [DeadCode](#deadcode) (44)
-- [DependencyInjection](#dependencyinjection) (2)
+- [DependencyInjection](#dependencyinjection) (1)
- [EarlyReturn](#earlyreturn) (10)
@@ -20,8 +20,6 @@
- [Naming](#naming) (6)
-- [PSR4](#psr4) (1)
-
- [Php52](#php52) (2)
- [Php53](#php53) (3)
@@ -44,11 +42,11 @@
- [Php80](#php80) (18)
-- [Php81](#php81) (12)
+- [Php81](#php81) (11)
- [Php82](#php82) (3)
-- [Privatization](#privatization) (5)
+- [Privatization](#privatization) (4)
- [Removing](#removing) (6)
@@ -56,9 +54,9 @@
- [Renaming](#renaming) (10)
-- [Strict](#strict) (6)
+- [Strict](#strict) (5)
-- [Transform](#transform) (27)
+- [Transform](#transform) (26)
- [TypeDeclaration](#typedeclaration) (40)
@@ -651,30 +649,13 @@ Change multiple null compares to ?? queue
Replaces static::* access to private constants with self::*
-:wrench: **configure it!**
-
- class: [`Rector\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector`](../rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php)
-```php
-ruleWithConfiguration(ConvertStaticPrivateConstantToSelfRector::class, [
- ConvertStaticPrivateConstantToSelfRector::ENABLE_FOR_NON_FINAL_CLASSES => false,
- ]);
-};
-```
-
-↓
-
```diff
- final class Foo {
+ final class Foo
+ {
private const BAR = 'bar';
+
public function run()
{
- $bar = static::BAR;
@@ -2971,27 +2952,8 @@ Remove unused parent call with no parent class
Remove unneeded PHP_VERSION_ID conditional checks
-:wrench: **configure it!**
-
- class: [`Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector`](../rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php)
-```php
-ruleWithConfiguration(RemovePhpVersionIdCheckRector::class, [
- 80000,
- ]);
-};
-```
-
-↓
-
```diff
class SomeClass
{
@@ -3155,27 +3117,8 @@ Remove unused private method
Remove unused private properties
-:wrench: **configure it!**
-
- class: [`Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector`](../rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php)
-```php
-ruleWithConfiguration(RemoveUnusedPrivatePropertyRector::class, [
- RemoveUnusedPrivatePropertyRector::REMOVE_ASSIGN_SIDE_EFFECT => true,
- ]);
-};
-```
-
-↓
-
```diff
class SomeClass
{
@@ -3369,31 +3312,6 @@ Remove php version checks if they are passed
## DependencyInjection
-### ActionInjectionToConstructorInjectionRector
-
-Turns action injection in Controllers to constructor injection
-
-- class: [`Rector\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector`](../rules/DependencyInjection/Rector/Class_/ActionInjectionToConstructorInjectionRector.php)
-
-```diff
- final class SomeController
- {
-- public function default(ProductRepository $productRepository)
-+ public function __construct(
-+ private ProductRepository $productRepository
-+ ) {
-+ }
-+
-+ public function default()
- {
-- $products = $productRepository->fetchAll();
-+ $products = $this->productRepository->fetchAll();
- }
- }
-```
-
-
-
### AddMethodParentCallRector
Add method parent call, in case new parent method is added
@@ -3918,36 +3836,6 @@ Rename variable to match new ClassType
-## PSR4
-
-### MultipleClassFileToPsr4ClassesRector
-
-Change multiple classes in one file to standalone PSR-4 classes.
-
-- class: [`Rector\PSR4\Rector\Namespace_\MultipleClassFileToPsr4ClassesRector`](../rules/PSR4/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector.php)
-
-```diff
-+// new file: "app/Exceptions/FirstException.php"
- namespace App\Exceptions;
-
- use Exception;
-
- final class FirstException extends Exception
- {
- }
-+
-+// new file: "app/Exceptions/SecondException.php"
-+namespace App\Exceptions;
-+
-+use Exception;
-
- final class SecondException extends Exception
- {
- }
-```
-
-
-
## Php52
### ContinueToBreakInSwitchRector
@@ -5797,26 +5685,6 @@ Add `Stringable` interface to classes with `__toString()` method
## Php81
-### ConstantListClassToEnumRector
-
-Upgrade constant list classes to full blown enum
-
-- class: [`Rector\Php81\Rector\Class_\ConstantListClassToEnumRector`](../rules/Php81/Rector/Class_/ConstantListClassToEnumRector.php)
-
-```diff
--class Direction
-+enum Direction
- {
-- public const LEFT = 'left';
-+ case LEFT;
-
-- public const RIGHT = 'right';
-+ case RIGHT;
- }
-```
-
-
-
### FinalizePublicClassConstantRector
Add final to constants that does not have children
@@ -6092,34 +5960,6 @@ Change deprecated utf8_decode and utf8_encode to mb_convert_encoding
## Privatization
-### ChangeGlobalVariablesToPropertiesRector
-
-Change global `$variables` to private properties
-
-- class: [`Rector\Privatization\Rector\Class_\ChangeGlobalVariablesToPropertiesRector`](../rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php)
-
-```diff
- class SomeClass
- {
-+ private $variable;
- public function go()
- {
-- global $variable;
-- $variable = 5;
-+ $this->variable = 5;
- }
-
- public function run()
- {
-- global $variable;
-- var_dump($variable);
-+ var_dump($this->variable);
- }
- }
-```
-
-
-
### FinalizeClassesWithoutChildrenRector
Finalize every class that has no children
@@ -6811,27 +6651,6 @@ return static function (RectorConfig $rectorConfig): void {
## Strict
-### AddConstructorParentCallRector
-
-Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\Classes\RequireParentConstructCallRule"
-
-- class: [`Rector\Strict\Rector\ClassMethod\AddConstructorParentCallRector`](../rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php)
-
-```diff
- class SunshineCommand extends ParentClassWithConstructor
- {
-- public function __construct()
-+ public function __construct(ParentDependency $parentDependency)
- {
- $value = 5;
-+
-+ parent::__construct($parentDependency);
- }
- }
-```
-
-
-
### BooleanInBooleanNotRuleFixerRector
Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule"
@@ -7547,55 +7366,6 @@ return static function (RectorConfig $rectorConfig): void {
-### NewToConstructorInjectionRector
-
-Change defined new type to constructor injection
-
-:wrench: **configure it!**
-
-- class: [`Rector\Transform\Rector\New_\NewToConstructorInjectionRector`](../rules/Transform/Rector/New_/NewToConstructorInjectionRector.php)
-
-```php
-ruleWithConfiguration(NewToConstructorInjectionRector::class, [
- 'Validator',
- ]);
-};
-```
-
-↓
-
-```diff
- class SomeClass
- {
-+ /**
-+ * @var Validator
-+ */
-+ private $validator;
-+
-+ public function __construct(Validator $validator)
-+ {
-+ $this->validator = $validator;
-+ }
-+
- public function run()
- {
-- $validator = new Validator();
-- $validator->validate(1000);
-+ $this->validator->validate(1000);
- }
- }
-```
-
-
-
### NewToStaticCallRector
Change new Object to static call
diff --git a/config/set/code-quality.php b/config/set/code-quality.php
index 9a43aafe5b1..cf1e8ee88cf 100644
--- a/config/set/code-quality.php
+++ b/config/set/code-quality.php
@@ -79,6 +79,7 @@
use Rector\Config\RectorConfig;
use Rector\Php52\Rector\Property\VarToPublicPropertyRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
+use Rector\RemovingStatic\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
@@ -188,5 +189,6 @@
CleanupUnneededNullsafeOperatorRector::class,
DisallowedEmptyRuleFixerRector::class,
ConvertStaticPrivateConstantToSelfRector::class,
+ LocallyCalledStaticMethodToNonStaticRector::class,
]);
};
diff --git a/config/set/dead-code.php b/config/set/dead-code.php
index d9685a9a995..7c1905f3d53 100644
--- a/config/set/dead-code.php
+++ b/config/set/dead-code.php
@@ -19,6 +19,7 @@
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector;
+use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
use Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector;
use Rector\DeadCode\Rector\For_\RemoveDeadContinueRector;
@@ -95,5 +96,6 @@
RemoveAlwaysTrueIfConditionRector::class,
RemoveDeadZeroAndOneOperationRector::class,
+ RemovePhpVersionIdCheckRector::class,
]);
};
diff --git a/easy-ci.php b/easy-ci.php
index 515bb377aef..52edcca85d2 100644
--- a/easy-ci.php
+++ b/easy-ci.php
@@ -12,27 +12,18 @@
use Rector\Core\Contract\PHPStan\Reflection\TypeToCallReflectionResolver\TypeToCallReflectionResolverInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Contract\Rector\RectorInterface;
-use Rector\Core\Contract\Template\TemplateResolverInterface;
-use Rector\Core\NodeAnalyzer\CoalesceAnalyzer;
-use Rector\Core\NodeDecorator\NamespacedNameDecorator;
use Rector\Core\NodeManipulator\MethodCallManipulator;
-use Rector\Core\PhpParser\Node\NamedVariableFactory;
use Rector\DependencyInjection\NodeManipulator\PropertyConstructorInjectionManipulator;
use Rector\FileSystemRector\Parser\FileInfoParser;
use Rector\Naming\Contract\AssignVariableNameResolverInterface;
use Rector\Naming\Contract\Guard\ConflictingNameGuardInterface;
-use Rector\NodeCollector\BinaryOpTreeRootLocator;
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
use Rector\NodeTypeResolver\Reflection\BetterReflection\RectorBetterReflectionSourceLocatorFactory;
-use Rector\NodeTypeResolver\TypeAnalyzer\MethodTypeAnalyzer;
use Rector\Php80\Contract\AttributeDecoratorInterface;
-use Rector\Php80\Contract\StrStartWithMatchAndRefactorInterface;
-use Rector\Php81\NodeFactory\ClassFromEnumFactory;
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
-use Rector\PhpAttribute\NodeFactory\DoctrineAnnotationFactory;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\AbstractPhpDocNodeVisitor;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\ReadWrite\Contract\ParentNodeReadAnalyzerInterface;
@@ -59,7 +50,6 @@
TypeToCallReflectionResolverInterface::class,
FileProcessorInterface::class,
ClassNameImportSkipVoterInterface::class,
- StrStartWithMatchAndRefactorInterface::class,
PhpDocTypeMapperInterface::class,
PhpParserNodeMapperInterface::class,
TypeMapperInterface::class,
diff --git a/phpstan.neon b/phpstan.neon
index 4bb659cd190..9bf30b6048a 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -712,3 +712,6 @@ parameters:
- '#Call to deprecated method findParentType#'
- '#Call to deprecated method findParentByTypes#'
- '#Instantiation of deprecated class Rector\\Core\\DependencyInjection\\CompilerPass\\AutowireArrayParameterCompilerPass#'
+
+ # handle later
+ - '#Fetching class constant class of deprecated class Rector\\(.*?)#'
diff --git a/rector.php b/rector.php
index e814b006735..39e567463a5 100644
--- a/rector.php
+++ b/rector.php
@@ -91,6 +91,10 @@
\Rector\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector::class => [
__DIR__ . '/src/DependencyInjection',
],
+
+ \Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector::class => [
+ __DIR__ . '/src/Util/FileHasher.php',
+ ],
]);
$rectorConfig->phpstanConfig(__DIR__ . '/phpstan-for-rector.neon');
diff --git a/rules-tests/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector/config/configured_rule.php b/rules-tests/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector/config/configured_rule.php
index 05eaa31cab3..b4b63f34bbd 100644
--- a/rules-tests/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector/config/configured_rule.php
+++ b/rules-tests/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector/config/configured_rule.php
@@ -7,6 +7,6 @@
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
return static function (RectorConfig $rectorConfig): void {
- $rectorConfig
- ->ruleWithConfiguration(RemovePhpVersionIdCheckRector::class, [PhpVersion::PHP_80]);
+ $rectorConfig->rule(RemovePhpVersionIdCheckRector::class);
+ $rectorConfig->phpVersion(PhpVersion::PHP_80);
};
diff --git a/rules-tests/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector/Fixture/skip_private_static_call.php.inc b/rules-tests/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector/Fixture/skip_private_static_call.php.inc
new file mode 100644
index 00000000000..f48a2a3fdeb
--- /dev/null
+++ b/rules-tests/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector/Fixture/skip_private_static_call.php.inc
@@ -0,0 +1,18 @@
+getConstants(), true)) {
- return;
- }
-
- // ensure cast to (string) first to allow string like "8.0" value to be converted to the int value
- /** @var PhpVersion::* $phpVersion */
- $this->phpVersion = $phpVersion;
+ $this->phpVersion = $this->phpVersionProvider->provide();
}
public function getRuleDefinition(): RuleDefinition
@@ -63,7 +41,7 @@ public function getRuleDefinition(): RuleDefinition
return new RuleDefinition(
'Remove unneeded PHP_VERSION_ID conditional checks',
[
- new ConfiguredCodeSample(
+ new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
@@ -87,8 +65,6 @@ public function run()
}
}
CODE_SAMPLE
- ,
- [PhpVersion::PHP_80]
),
],
);
diff --git a/rules/Php80/Rector/Identical/StrStartsWithRector.php b/rules/Php80/Rector/Identical/StrStartsWithRector.php
index d70f3e82cb6..0bd93958990 100644
--- a/rules/Php80/Rector/Identical/StrStartsWithRector.php
+++ b/rules/Php80/Rector/Identical/StrStartsWithRector.php
@@ -12,6 +12,9 @@
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php80\Contract\StrStartWithMatchAndRefactorInterface;
+use Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor\StrncmpMatchAndRefactor;
+use Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor\StrposMatchAndRefactor;
+use Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor\SubstrMatchAndRefactor;
use Rector\Php80\ValueObject\StrStartsWith;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -28,11 +31,20 @@
final class StrStartsWithRector extends AbstractRector implements MinPhpVersionInterface
{
/**
- * @param StrStartWithMatchAndRefactorInterface[] $strStartWithMatchAndRefactors
+ * @var StrStartWithMatchAndRefactorInterface[]
*/
+ private array $strStartWithMatchAndRefactors = [];
+
public function __construct(
- private readonly array $strStartWithMatchAndRefactors
+ StrncmpMatchAndRefactor $strncmpMatchAndRefactor,
+ SubstrMatchAndRefactor $substrMatchAndRefactor,
+ StrposMatchAndRefactor $strposMatchAndRefactor,
) {
+ $this->strStartWithMatchAndRefactors = [
+ $strncmpMatchAndRefactor,
+ $substrMatchAndRefactor,
+ $strposMatchAndRefactor,
+ ];
}
public function provideMinPhpVersion(): int
diff --git a/rules/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php b/rules/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php
index df81d8bead9..08b175f74be 100644
--- a/rules/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php
+++ b/rules/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php
@@ -8,10 +8,9 @@
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
-use PhpParser\Node\Stmt\ClassLike;
+use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
-use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
@@ -75,26 +74,35 @@ private function someStatic()
*/
public function getNodeTypes(): array
{
- return [ClassMethod::class, StaticCall::class];
+ return [Class_::class];
}
/**
- * @param ClassMethod|StaticCall $node
+ * @param Class_ $node
*/
- public function refactor(Node $node): ?Node
+ public function refactor(Node $node): ?Class_
{
- if ($node instanceof ClassMethod) {
- if (! $node->isPrivate()) {
- return null;
+ $hasChanged = false;
+
+ foreach ($node->getMethods() as $classMethod) {
+ if (! $classMethod->isPrivate()) {
+ continue;
+ }
+
+ $changedClassMethod = $this->refactorClassMethod($node, $classMethod);
+ if ($changedClassMethod instanceof ClassMethod) {
+ $hasChanged = true;
}
+ }
- return $this->refactorClassMethod($node);
+ if ($hasChanged) {
+ return $node;
}
- return $this->refactorStaticCall($node);
+ return null;
}
- private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod
+ private function refactorClassMethod(Class_ $class, ClassMethod $classMethod): ?ClassMethod
{
if (! $classMethod->isStatic()) {
return null;
@@ -109,60 +117,75 @@ private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod
return null;
}
- // change static calls to non-static ones, but only if in non-static method!!!
- $this->visibilityManipulator->makeNonStatic($classMethod);
-
- return $classMethod;
- }
-
- private function refactorStaticCall(StaticCall $staticCall): ?MethodCall
- {
- $classLike = $this->betterNodeFinder->findParentType($staticCall, ClassLike::class);
- if (! $classLike instanceof ClassLike) {
+ if ($this->isClassMethodCalledInAnotherStaticClassMethod($class, $classMethod)) {
return null;
}
- /** @var ClassMethod[] $classMethods */
- $classMethods = $this->betterNodeFinder->findInstanceOf($classLike, ClassMethod::class);
+ // replace all the calls
+ $classMethodName = $this->getName($classMethod);
+ $this->traverseNodesWithCallable($class, function (Node $node) use ($classMethodName): ?MethodCall {
+ if (! $node instanceof StaticCall) {
+ return null;
+ }
- foreach ($classMethods as $classMethod) {
- if (! $this->isClassMethodMatchingStaticCall($classMethod, $staticCall)) {
- continue;
+ if (! $this->isName($node->class, 'self')) {
+ return null;
}
- if ($this->isInStaticClassMethod($staticCall)) {
- continue;
+ if (! $this->isName($node->name, $classMethodName)) {
+ return null;
}
- $thisVariable = new Variable('this');
- return new MethodCall($thisVariable, $staticCall->name, $staticCall->args);
- }
+ return new MethodCall(new Variable('this'), $classMethodName);
+ });
- return null;
+ // change static calls to non-static ones, but only if in non-static method!!!
+ $this->visibilityManipulator->makeNonStatic($classMethod);
+ return $classMethod;
}
- private function isInStaticClassMethod(StaticCall $staticCall): bool
+ /**
+ * If the static class method is called in another static class method,
+ * we should keep it to avoid calling $this in static
+ */
+ private function isClassMethodCalledInAnotherStaticClassMethod(Class_ $class, ClassMethod $classMethod): bool
{
- $locationClassMethod = $this->betterNodeFinder->findParentType($staticCall, ClassMethod::class);
- if (! $locationClassMethod instanceof ClassMethod) {
- return false;
- }
+ $currentClassMethodName = $this->getName($classMethod);
- return $locationClassMethod->isStatic();
- }
+ $isInsideStaticClassMethod = false;
- private function isClassMethodMatchingStaticCall(ClassMethod $classMethod, StaticCall $staticCall): bool
- {
- $classLike = $this->betterNodeFinder->findParentType($classMethod, ClassLike::class);
- if (! $classLike instanceof ClassLike) {
- return false;
- }
+ // check if called stati call somewhere in class, but only in static methods
+ foreach ($class->getMethods() as $checkedClassMethod) {
+ // not a problem
+ if (! $checkedClassMethod->isStatic()) {
+ continue;
+ }
+
+ $this->traverseNodesWithCallable($checkedClassMethod, function (Node $node) use (
+ $currentClassMethodName,
+ &$isInsideStaticClassMethod
+ ): ?StaticCall {
+ if (! $node instanceof StaticCall) {
+ return null;
+ }
- $className = (string) $this->nodeNameResolver->getName($classLike);
+ if (! $this->isName($node->class, 'self')) {
+ return null;
+ }
- $objectType = new ObjectType($className);
- $callerType = $this->nodeTypeResolver->getType($staticCall->class);
+ if (! $this->isName($node->name, $currentClassMethodName)) {
+ return null;
+ }
+
+ $isInsideStaticClassMethod = true;
+ return $node;
+ });
+
+ if ($isInsideStaticClassMethod) {
+ return $isInsideStaticClassMethod;
+ }
+ }
- return $objectType->equals($callerType);
+ return false;
}
}
diff --git a/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php b/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php
index bcd1ada29dd..5ba60870c4b 100644
--- a/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php
+++ b/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php
@@ -17,6 +17,7 @@
/**
* @changelog https://github.com/doctrine/dbal/blob/3.1.x/src/Types/Types.php
*
+ * @api used in rector-doctrine
* @see \Rector\Tests\Transform\Rector\Attribute\AttributeKeyToClassConstFetchRector\AttributeKeyToClassConstFetchRectorTest
*/
final class AttributeKeyToClassConstFetchRector extends AbstractRector implements ConfigurableRectorInterface
diff --git a/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php b/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php
index a4d8b5111c6..8dea5781381 100644
--- a/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php
+++ b/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php
@@ -16,6 +16,7 @@
use Webmozart\Assert\Assert;
/**
+ * @api used in rector-doctrine
* @see \Rector\Tests\Transform\Rector\Class_\AddInterfaceByTraitRector\AddInterfaceByTraitRectorTest
*/
final class AddInterfaceByTraitRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
diff --git a/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php b/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php
index 416a7ecb574..9b80acf98dc 100644
--- a/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php
+++ b/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php
@@ -15,6 +15,7 @@
use Webmozart\Assert\Assert;
/**
+ * @deprecated rather for downgrade-php, but still a comment, so not useful
* @changelog https://wiki.php.net/rfc/deprecate_dynamic_properties
*
* @see \Rector\Tests\Transform\Rector\Class_\RemoveAllowDynamicPropertiesAttributeRector\RemoveAllowDynamicPropertiesAttributeRectorTest
diff --git a/rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.php b/rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.php
index ed749efdd66..717ae5c7c57 100644
--- a/rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.php
+++ b/rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.php
@@ -16,6 +16,7 @@
use Webmozart\Assert\Assert;
/**
+ * @deprecated Used for custom project, not practical
* @see \Rector\Tests\Transform\Rector\Isset_\UnsetAndIssetToMethodCallRector\UnsetAndIssetToMethodCallRectorTest
*/
final class UnsetAndIssetToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
diff --git a/src/Console/Command/WorkerCommand.php b/src/Console/Command/WorkerCommand.php
index 68c76b41707..6bb2c7f1661 100644
--- a/src/Console/Command/WorkerCommand.php
+++ b/src/Console/Command/WorkerCommand.php
@@ -35,7 +35,7 @@ public function __construct(
protected function configure(): void
{
$this->setName('worker');
- $this->setDescription('(Internal) Support for parallel process');
+ $this->setDescription('[INTERNAL] Support for parallel process');
parent::configure();
}
diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php
index 4d05c4621b5..c8f014962d6 100644
--- a/src/Console/ConsoleApplication.php
+++ b/src/Console/ConsoleApplication.php
@@ -8,6 +8,14 @@
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Application\VersionResolver;
use Rector\Core\Configuration\Option;
+use Rector\Core\Console\Command\ListRulesCommand;
+use Rector\Core\Console\Command\ProcessCommand;
+use Rector\Core\Console\Command\SetupCICommand;
+use Rector\Core\Console\Command\WorkerCommand;
+use Rector\RectorGenerator\Command\GenerateCommand;
+use Rector\RectorGenerator\Command\InitRecipeCommand;
+use Rector\Utils\Command\MissingInSetCommand;
+use Rector\Utils\Command\OutsideAnySetCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
@@ -22,14 +30,37 @@ final class ConsoleApplication extends Application
*/
private const NAME = 'Rector';
- /**
- * @param Command[] $commands
- */
- public function __construct(array $commands = [])
- {
+ public function __construct(
+ ProcessCommand $processCommand,
+ WorkerCommand $workerCommand,
+ SetupCICommand $setupCICommand,
+ ListRulesCommand $listRulesCommand,
+ // dev
+ ?MissingInSetCommand $missingInSetCommand = null,
+ ?OutsideAnySetCommand $outsideAnySetCommand = null,
+ ?GenerateCommand $generateCommand = null,
+ ?InitRecipeCommand $initRecipeCommand = null,
+ ) {
parent::__construct(self::NAME, VersionResolver::PACKAGE_VERSION);
- $this->addCommands($commands);
+ $this->addCommands([$processCommand, $workerCommand, $setupCICommand, $listRulesCommand]);
+
+ if ($missingInSetCommand instanceof Command) {
+ $this->add($missingInSetCommand);
+ }
+
+ if ($outsideAnySetCommand instanceof Command) {
+ $this->add($outsideAnySetCommand);
+ }
+
+ if ($generateCommand instanceof Command) {
+ $this->add($generateCommand);
+ }
+
+ if ($initRecipeCommand instanceof Command) {
+ $this->add($initRecipeCommand);
+ }
+
$this->setDefaultCommand('process');
}
diff --git a/src/Kernel/RectorKernel.php b/src/Kernel/RectorKernel.php
index 67f49fe9db1..4eae5f0abdf 100644
--- a/src/Kernel/RectorKernel.php
+++ b/src/Kernel/RectorKernel.php
@@ -17,7 +17,7 @@ final class RectorKernel
/**
* @var string
*/
- private const CACHE_KEY = 'v71';
+ private const CACHE_KEY = 'v72';
private ContainerInterface|null $container = null;
diff --git a/utils/Command/MissingInSetCommand.php b/utils/Command/MissingInSetCommand.php
index 285a2924b06..d6509c1df4e 100644
--- a/utils/Command/MissingInSetCommand.php
+++ b/utils/Command/MissingInSetCommand.php
@@ -47,6 +47,7 @@ final class MissingInSetCommand extends Command
__DIR__ . '/../../rules/Php81/Rector' => __DIR__ . '/../../config/set/php81.php',
__DIR__ . '/../../rules/Php82/Rector' => __DIR__ . '/../../config/set/php82.php',
__DIR__ . '/../../rules/Strict/Rector' => __DIR__ . '/../../config/set/strict-booleans.php',
+ // rector-downgrade
__DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp70' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php70.php',
__DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp71' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php71.php',
__DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp72' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php72.php',