diff --git a/config/set/dead-code/dead-code.yaml b/config/set/dead-code/dead-code.yaml index 1dfb5b9fbab6..f56fd83d0f56 100644 --- a/config/set/dead-code/dead-code.yaml +++ b/config/set/dead-code/dead-code.yaml @@ -32,4 +32,5 @@ services: Rector\DeadCode\Rector\Ternary\TernaryToBooleanOrFalseToBooleanAndRector: null Rector\PHPUnit\Rector\ClassMethod\RemoveEmptyTestMethodRector: null Rector\DeadCode\Rector\TryCatch\RemoveDeadTryCatchRector: null + Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector: null diff --git a/docs/AllRectorsOverview.md b/docs/AllRectorsOverview.md index 6d97fb6fe2cc..5c6dbf60e42c 100644 --- a/docs/AllRectorsOverview.md +++ b/docs/AllRectorsOverview.md @@ -1,4 +1,4 @@ -# All 460 Rectors Overview +# All 461 Rectors Overview - [Projects](#projects) - [General](#general) @@ -351,12 +351,13 @@ Changes method calls based on matching the first parameter value. ```yaml services: Rector\CakePHP\Rector\MethodCall\RenameMethodCallBasedOnParameterRector: - getParam: - match_parameter: paging - replace_with: getAttribute - withParam: - match_parameter: paging - replace_with: withAttribute + $methodNamesByTypes: + getParam: + match_parameter: paging + replace_with: getAttribute + withParam: + match_parameter: paging + replace_with: withAttribute ``` ↓ @@ -2936,6 +2937,26 @@ Remove unreachable statements
+### `RemoveUnusedClassConstantRector` + +- class: [`Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector`](/../master/rules/dead-code/src/Rector/ClassConst/RemoveUnusedClassConstantRector.php) +- [test fixtures](/../master/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture) + +Remove unused class constants + +```diff + class SomeClass + { +- private const SOME_CONST = 'dead'; +- + public function run() + { + } + } +``` + +
+ ### `RemoveUnusedClassesRector` - class: [`Rector\DeadCode\Rector\Class_\RemoveUnusedClassesRector`](/../master/rules/dead-code/src/Rector/Class_/RemoveUnusedClassesRector.php) diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/BlameableTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/BlameableTagValueNode.php index 513a0a64c428..baaab898a35f 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/BlameableTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/BlameableTagValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\Blameable; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class BlameableTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Blameable::class; - /** * @var string|null */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/LocaleTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/LocaleTagValueNode.php index b6ff70c17f8d..dd2219e58c4c 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/LocaleTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/LocaleTagValueNode.php @@ -4,16 +4,10 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\Locale; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class LocaleTagValueNode extends AbstractTagValueNode { - /** - * @var string - */ - public const CLASS_NAME = Locale::class; - public function __toString(): string { return ''; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/LoggableTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/LoggableTagValueNode.php index 997139876cf8..81b824c8dcec 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/LoggableTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/LoggableTagValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\Loggable; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class LoggableTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Loggable::class; - /** * @var string|null */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/SlugTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/SlugTagValueNode.php index c66ecaf50612..979cbd66df2f 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/SlugTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/SlugTagValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\Slug; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class SlugTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Slug::class; - /** * @var mixed[] */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/SoftDeleteableTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/SoftDeleteableTagValueNode.php index 54de14849fd4..23bcf41d6c54 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/SoftDeleteableTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/SoftDeleteableTagValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\SoftDeleteable; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class SoftDeleteableTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = SoftDeleteable::class; - /** * @var string */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TranslatableTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TranslatableTagValueNode.php index 1181af945d16..862c575700b6 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TranslatableTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TranslatableTagValueNode.php @@ -4,16 +4,10 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\Translatable; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class TranslatableTagValueNode extends AbstractTagValueNode { - /** - * @var string - */ - public const CLASS_NAME = Translatable::class; - public function __toString(): string { return ''; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeLeftTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeLeftTagValueNode.php index 1e3e33f0fb03..865436175b62 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeLeftTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeLeftTagValueNode.php @@ -4,16 +4,10 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\TreeLeft; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class TreeLeftTagValueNode extends AbstractTagValueNode { - /** - * @var string - */ - public const CLASS_NAME = TreeLeft::class; - public function __toString(): string { return ''; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeLevelTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeLevelTagValueNode.php index f60cba078cf7..95771da53de2 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeLevelTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeLevelTagValueNode.php @@ -4,16 +4,10 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\TreeLevel; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class TreeLevelTagValueNode extends AbstractTagValueNode { - /** - * @var string - */ - public const CLASS_NAME = TreeLevel::class; - public function __toString(): string { return ''; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeParentTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeParentTagValueNode.php index 41f6a701be32..d432691e7bcd 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeParentTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeParentTagValueNode.php @@ -4,16 +4,10 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\TreeParent; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class TreeParentTagValueNode extends AbstractTagValueNode { - /** - * @var string - */ - public const CLASS_NAME = TreeParent::class; - public function __toString(): string { return ''; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeRightTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeRightTagValueNode.php index 085fa18a555a..076216ccaeaf 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeRightTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeRightTagValueNode.php @@ -4,16 +4,10 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\TreeRight; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class TreeRightTagValueNode extends AbstractTagValueNode { - /** - * @var string - */ - public const CLASS_NAME = TreeRight::class; - public function __toString(): string { return ''; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeRootTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeRootTagValueNode.php index c07e986a18d3..0d71e8b7e1ff 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeRootTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeRootTagValueNode.php @@ -4,16 +4,10 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\TreeRoot; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class TreeRootTagValueNode extends AbstractTagValueNode { - /** - * @var string - */ - public const CLASS_NAME = TreeRoot::class; - public function __toString(): string { return ''; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeTagValueNode.php index ff6830cd7e24..cb6d38d3a874 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/TreeTagValueNode.php @@ -4,16 +4,10 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\Tree; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class TreeTagValueNode extends AbstractTagValueNode { - /** - * @var string - */ - public const CLASS_NAME = Tree::class; - /** * @var string */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/VersionedTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/VersionedTagValueNode.php index aa9ad48d227d..5d687203f9b8 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/VersionedTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Gedmo/VersionedTagValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\Gedmo; -use Gedmo\Mapping\Annotation\Versioned; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class VersionedTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Versioned::class; - public function __toString(): string { return ''; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSInjectParamsTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSInjectParamsTagValueNode.php index a8eb216ec915..1b98b8eaa0c3 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSInjectParamsTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSInjectParamsTagValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\JMS; -use JMS\DiExtraBundle\Annotation\InjectParams; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class JMSInjectParamsTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = InjectParams::class; - public function __construct(string $originalContent) { $this->originalContent = $originalContent; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSInjectTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSInjectTagValueNode.php index b5904ad3b2e4..b13ae321fede 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSInjectTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSInjectTagValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\JMS; -use JMS\DiExtraBundle\Annotation\Inject; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class JMSInjectTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Inject::class; - /** * @var string|null */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSServiceValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSServiceValueNode.php index 6d7ce7708c11..457532790059 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSServiceValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/JMS/JMSServiceValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\JMS; -use JMS\DiExtraBundle\Annotation\Service; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class JMSServiceValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Service::class; - public function __construct(string $originalContent) { $this->originalContent = $originalContent; diff --git a/packages/better-php-doc-parser/src/PhpDocNode/JMS/SerializerTypeTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/JMS/SerializerTypeTagValueNode.php index f1dbf2ddaf22..1b246c4f932c 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/JMS/SerializerTypeTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/JMS/SerializerTypeTagValueNode.php @@ -4,7 +4,6 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\JMS; -use JMS\Serializer\Annotation\Type; use Nette\Utils\Strings; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface; @@ -12,11 +11,6 @@ final class SerializerTypeTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Type::class; - /** * @var string */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/PHPDI/PHPDIInjectTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/PHPDI/PHPDIInjectTagValueNode.php index a4bc89c9e55e..cc5604246c57 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/PHPDI/PHPDIInjectTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/PHPDI/PHPDIInjectTagValueNode.php @@ -4,17 +4,11 @@ namespace Rector\BetterPhpDocParser\PhpDocNode\PHPDI; -use DI\Annotation\Inject; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; final class PHPDIInjectTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Inject::class; - /** * @var string|null */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Sensio/SensioMethodTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Sensio/SensioMethodTagValueNode.php index 745aae8a9c2f..30f6c226d638 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Sensio/SensioMethodTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Sensio/SensioMethodTagValueNode.php @@ -6,15 +6,9 @@ use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; final class SensioMethodTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Method::class; - /** * @var string[] */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Sensio/SensioTemplateTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Sensio/SensioTemplateTagValueNode.php index 5dc7622ead5b..3f8eeb9a0c82 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Sensio/SensioTemplateTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Sensio/SensioTemplateTagValueNode.php @@ -6,15 +6,9 @@ use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; final class SensioTemplateTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Template::class; - /** * @var string|null */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php index 54e81da1dd53..98dff090122c 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php @@ -7,15 +7,9 @@ use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface; use Rector\Symfony\PhpDocParser\Ast\PhpDoc\AbstractConstraintTagValueNode; -use Symfony\Component\Validator\Constraints\Choice; final class AssertChoiceTagValueNode extends AbstractConstraintTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Choice::class; - /** * @var mixed[]|string|null */ diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Symfony/Validator/Constraints/AssertTypeTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Symfony/Validator/Constraints/AssertTypeTagValueNode.php index d0b6c3e0805a..a2260d84aa24 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Symfony/Validator/Constraints/AssertTypeTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Symfony/Validator/Constraints/AssertTypeTagValueNode.php @@ -6,15 +6,9 @@ use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\Symfony\PhpDocParser\Ast\PhpDoc\AbstractConstraintTagValueNode; -use Symfony\Component\Validator\Constraints\Type; final class AssertTypeTagValueNode extends AbstractConstraintTagValueNode implements ShortNameAwareTagInterface { - /** - * @var string - */ - public const CLASS_NAME = Type::class; - /** * @var string */ diff --git a/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php b/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php index 7cdf38666c96..9ed42ab5e684 100644 --- a/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php +++ b/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php @@ -53,13 +53,15 @@ public function getDefinition(): RectorDefinition PHP , [ - 'getParam' => [ - 'match_parameter' => 'paging', - 'replace_with' => 'getAttribute', - ], - 'withParam' => [ - 'match_parameter' => 'paging', - 'replace_with' => 'withAttribute', + '$methodNamesByTypes' => [ + 'getParam' => [ + 'match_parameter' => 'paging', + 'replace_with' => 'getAttribute', + ], + 'withParam' => [ + 'match_parameter' => 'paging', + 'replace_with' => 'withAttribute', + ], ], ] ), diff --git a/rules/dead-code/src/Rector/ClassConst/RemoveUnusedClassConstantRector.php b/rules/dead-code/src/Rector/ClassConst/RemoveUnusedClassConstantRector.php new file mode 100644 index 000000000000..1a312aa10233 --- /dev/null +++ b/rules/dead-code/src/Rector/ClassConst/RemoveUnusedClassConstantRector.php @@ -0,0 +1,101 @@ +classConstParsedNodesFinder = $classConstParsedNodesFinder; + } + + public function getDefinition(): RectorDefinition + { + return new RectorDefinition('Remove unused class constants', [ + new CodeSample( + <<<'PHP' +class SomeClass +{ + private const SOME_CONST = 'dead'; + + public function run() + { + } +} +PHP +, + <<<'PHP' +class SomeClass +{ + public function run() + { + } +} +PHP + + ), + ]); + } + + /** + * @return string[] + */ + public function getNodeTypes(): array + { + return [ClassConst::class]; + } + + /** + * @param ClassConst $node + */ + public function refactor(Node $node): ?Node + { + if (count($node->consts) !== 1) { + return null; + } + + /** @var string $class */ + $class = $node->getAttribute(AttributeKey::CLASS_NAME); + + // 0. constants declared in interfaces have to be public + if ($this->classLikeParsedNodesFinder->findInterface($class) !== null) { + $this->makePublic($node); + return $node; + } + + /** @var string $constant */ + $constant = $this->getName($node); + + $directUseClasses = $this->classConstParsedNodesFinder->findDirectClassConstantFetches($class, $constant); + if ($directUseClasses !== []) { + return null; + } + + $indirectUseClasses = $this->classConstParsedNodesFinder->findIndirectClassConstantFetches($class, $constant); + if ($indirectUseClasses !== []) { + return null; + } + + $this->removeNode($node); + + return null; + } +} diff --git a/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/external_public.php.inc b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/external_public.php.inc new file mode 100644 index 000000000000..69b0b88f7bc3 --- /dev/null +++ b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/external_public.php.inc @@ -0,0 +1,20 @@ + +----- + diff --git a/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/fixture.php.inc b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/fixture.php.inc new file mode 100644 index 000000000000..6875c6d11bec --- /dev/null +++ b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/fixture.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/skip_child_used.php.inc b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/skip_child_used.php.inc new file mode 100644 index 000000000000..f3343b5653d0 --- /dev/null +++ b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/Fixture/skip_child_used.php.inc @@ -0,0 +1,16 @@ +doTestFile($file); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return RemoveUnusedClassConstantRector::class; + } +} diff --git a/rules/solid/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php b/rules/solid/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php index 3ae2f433ba8b..de49df538954 100644 --- a/rules/solid/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php +++ b/rules/solid/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php @@ -188,7 +188,7 @@ private function changeConstantVisibility( ?ConstantVisibility $constantVisibility, string $class ): void { - // 1. is actually never used (@todo use in "dead-code" set) + // 1. is actually never used if ($directUseClasses === []) { if ($indirectUseClasses !== [] && $constantVisibility !== null) { $this->makePrivateOrWeaker($classConst, $constantVisibility);