diff --git a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/ConstantListClassToEnumRectorTest.php b/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/ConstantListClassToEnumRectorTest.php deleted file mode 100644 index 5d9d1c85981..00000000000 --- a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/ConstantListClassToEnumRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/change_param_type.php.inc b/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/change_param_type.php.inc deleted file mode 100644 index 65c526b5aac..00000000000 --- a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/change_param_type.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/change_return_type.php.inc b/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/change_return_type.php.inc deleted file mode 100644 index 2ff26341702..00000000000 --- a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/change_return_type.php.inc +++ /dev/null @@ -1,34 +0,0 @@ - ------ - diff --git a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/enum_no_namespace.php.inc b/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/enum_no_namespace.php.inc deleted file mode 100644 index 9385780beb4..00000000000 --- a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/enum_no_namespace.php.inc +++ /dev/null @@ -1,20 +0,0 @@ - ------ - diff --git a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/enum_type_property.php.inc b/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/enum_type_property.php.inc deleted file mode 100644 index 55c37c3da6b..00000000000 --- a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/enum_type_property.php.inc +++ /dev/null @@ -1,28 +0,0 @@ - ------ - diff --git a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/multiple_params_change.php.inc b/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/multiple_params_change.php.inc deleted file mode 100644 index 551420d0a3c..00000000000 --- a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/multiple_params_change.php.inc +++ /dev/null @@ -1,38 +0,0 @@ - ------ - diff --git a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/skip_also_other_elements.php.inc b/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/skip_also_other_elements.php.inc deleted file mode 100644 index decd9d1f820..00000000000 --- a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Fixture/skip_also_other_elements.php.inc +++ /dev/null @@ -1,12 +0,0 @@ - ------ - diff --git a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Source/Gear.php b/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Source/Gear.php deleted file mode 100644 index 1e82de8b250..00000000000 --- a/rules-tests/Php81/Rector/Class_/ConstantListClassToEnumRector/Source/Gear.php +++ /dev/null @@ -1,12 +0,0 @@ -rule(ConstantListClassToEnumRector::class); -}; diff --git a/rules/Php80/NodeAnalyzer/EnumParamAnalyzer.php b/rules/Php80/NodeAnalyzer/EnumParamAnalyzer.php deleted file mode 100644 index b7f6ab4b669..00000000000 --- a/rules/Php80/NodeAnalyzer/EnumParamAnalyzer.php +++ /dev/null @@ -1,94 +0,0 @@ -getParamTagValueByName($parameterReflection->getName()); - if (! $paramTagValueNode instanceof ParamTagValueNode) { - return null; - } - - $className = $this->resolveClassFromConstType($paramTagValueNode->type); - if ($className === null) { - return null; - } - - if (! $this->reflectionProvider->hasClass($className)) { - return null; - } - - return new ClassNameAndTagValueNode($className, $paramTagValueNode); - } - - public function matchReturnClassName(PhpDocInfo $phpDocInfo): ?ClassNameAndTagValueNode - { - $returnTagValueNode = $phpDocInfo->getReturnTagValue(); - if (! $returnTagValueNode instanceof ReturnTagValueNode) { - return null; - } - - $className = $this->resolveClassFromConstType($returnTagValueNode->type); - if (! is_string($className)) { - return null; - } - - return new ClassNameAndTagValueNode($className, $returnTagValueNode); - } - - public function matchPropertyClassName(PhpDocInfo $phpDocInfo): ?ClassNameAndTagValueNode - { - $varTagValueNode = $phpDocInfo->getVarTagValueNode(); - if (! $varTagValueNode instanceof VarTagValueNode) { - return null; - } - - $className = $this->resolveClassFromConstType($varTagValueNode->type); - if (! is_string($className)) { - return null; - } - - return new ClassNameAndTagValueNode($className, $varTagValueNode); - } - - private function resolveClassFromConstType(TypeNode $typeNode): ?string - { - if (! $typeNode instanceof ConstTypeNode) { - return null; - } - - if (! $typeNode->constExpr instanceof ConstFetchNode) { - return null; - } - - $constExpr = $typeNode->constExpr; - return $constExpr->getAttribute(PhpDocAttributeKey::RESOLVED_CLASS); - } -} diff --git a/rules/Php80/ValueObject/ClassNameAndTagValueNode.php b/rules/Php80/ValueObject/ClassNameAndTagValueNode.php deleted file mode 100644 index a958ee223d0..00000000000 --- a/rules/Php80/ValueObject/ClassNameAndTagValueNode.php +++ /dev/null @@ -1,28 +0,0 @@ -enumClass; - } - - public function getTagValueNode(): ParamTagValueNode|ReturnTagValueNode|VarTagValueNode - { - return $this->tagValueNode; - } -} diff --git a/rules/Php81/NodeAnalyzer/EnumConstListClassDetector.php b/rules/Php81/NodeAnalyzer/EnumConstListClassDetector.php deleted file mode 100644 index 135f579d41a..00000000000 --- a/rules/Php81/NodeAnalyzer/EnumConstListClassDetector.php +++ /dev/null @@ -1,91 +0,0 @@ -getConstants(); - - // must have at least 2 constants, otherwise probably not enum - if (count($classConstants) < 2) { - return false; - } - - // only constants are allowed, nothing else - if (count($class->stmts) !== count($classConstants)) { - return false; - } - - // all constant must be public - if (! $this->hasExclusivelyPublicClassConsts($classConstants)) { - return false; - } - - // all constants must have exactly 1 value - foreach ($classConstants as $classConstant) { - if (count($classConstant->consts) !== 1) { - return false; - } - } - - // only scalar values are allowed - foreach ($classConstants as $classConstant) { - $onlyConstConst = $classConstant->consts[0]; - if (! $onlyConstConst->value instanceof Scalar) { - return false; - } - } - - $uniqueTypeClasses = $this->resolveClassConstTypes($classConstants); - - // must be exactly 1 type - return count($uniqueTypeClasses) === 1; - } - - /** - * @param ClassConst[] $classConsts - * @return array> - */ - private function resolveClassConstTypes(array $classConsts): array - { - $typeClasses = []; - - // all constants must have same type - foreach ($classConsts as $classConst) { - $const = $classConst->consts[0]; - $type = $this->nodeTypeResolver->getType($const->value); - $typeClasses[] = $type::class; - } - - return array_unique($typeClasses); - } - - /** - * @param ClassConst[] $classConsts - */ - private function hasExclusivelyPublicClassConsts(array $classConsts): bool - { - foreach ($classConsts as $classConst) { - if (! $classConst->isPublic()) { - return false; - } - } - - return true; - } -} diff --git a/rules/Php81/Rector/Class_/ConstantListClassToEnumRector.php b/rules/Php81/Rector/Class_/ConstantListClassToEnumRector.php deleted file mode 100644 index 42b39491c3e..00000000000 --- a/rules/Php81/Rector/Class_/ConstantListClassToEnumRector.php +++ /dev/null @@ -1,199 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Class_::class, ClassMethod::class, Property::class]; - } - - /** - * @param Class_|ClassMethod|Property $node - */ - public function refactor(Node $node): ?Node - { - if ($node instanceof Class_) { - if (! $this->enumConstListClassDetector->detect($node)) { - return null; - } - - return $this->enumFactory->createFromClass($node); - } - - if ($node instanceof ClassMethod) { - return $this->refactorClassMethod($node); - } - - return $this->refactorProperty($node); - } - - private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod - { - // enum param types doc requires a docblock - $phpDocInfo = $this->phpDocInfoFactory->createFromNode($classMethod); - if (! $phpDocInfo instanceof PhpDocInfo) { - return null; - } - - $methodReflection = $this->reflectionResolver->resolveMethodReflectionFromClassMethod($classMethod); - if (! $methodReflection instanceof MethodReflection) { - return null; - } - - // refactor params - $haveParamsChanged = $this->refactorParams($methodReflection, $phpDocInfo, $classMethod); - - $hasReturnChanged = $this->refactorReturn($phpDocInfo, $classMethod); - if ($haveParamsChanged) { - return $classMethod; - } - - if ($hasReturnChanged) { - return $classMethod; - } - - return null; - } - - private function getParamByName(ClassMethod $classMethod, string $desiredParamName): ?Param - { - foreach ($classMethod->params as $param) { - if (! $this->nodeNameResolver->isName($param, $desiredParamName)) { - continue; - } - - return $param; - } - - return null; - } - - private function refactorParams( - MethodReflection $methodReflection, - PhpDocInfo $phpDocInfo, - ClassMethod $classMethod - ): bool { - $hasNodeChanged = false; - - $parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants()); - foreach ($parametersAcceptor->getParameters() as $parameterReflection) { - $classNameAndTagValueNode = $this->enumParamAnalyzer->matchParameterClassName( - $parameterReflection, - $phpDocInfo - ); - if (! $classNameAndTagValueNode instanceof ClassNameAndTagValueNode) { - continue; - } - - $param = $this->getParamByName($classMethod, $parameterReflection->getName()); - if (! $param instanceof Param) { - continue; - } - - // change and remove - $param->type = new FullyQualified($classNameAndTagValueNode->getEnumClass()); - $hasNodeChanged = true; - - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $classNameAndTagValueNode->getTagValueNode()); - } - - return $hasNodeChanged; - } - - private function refactorReturn(PhpDocInfo $phpDocInfo, ClassMethod $classMethod): bool - { - $classNameAndTagValueNode = $this->enumParamAnalyzer->matchReturnClassName($phpDocInfo); - if (! $classNameAndTagValueNode instanceof ClassNameAndTagValueNode) { - return false; - } - - $classMethod->returnType = new FullyQualified($classNameAndTagValueNode->getEnumClass()); - - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $classNameAndTagValueNode->getTagValueNode()); - - return true; - } - - private function refactorProperty(Property $property): ?Property - { - $phpDocInfo = $this->phpDocInfoFactory->createFromNode($property); - if (! $phpDocInfo instanceof PhpDocInfo) { - return null; - } - - $classNameAndTagValueNode = $this->enumParamAnalyzer->matchPropertyClassName($phpDocInfo); - if (! $classNameAndTagValueNode instanceof ClassNameAndTagValueNode) { - return null; - } - - $property->type = new FullyQualified($classNameAndTagValueNode->getEnumClass()); - - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $classNameAndTagValueNode->getTagValueNode()); - - return $property; - } -} diff --git a/src/Kernel/RectorKernel.php b/src/Kernel/RectorKernel.php index d858a8cceac..1ef397ffea5 100644 --- a/src/Kernel/RectorKernel.php +++ b/src/Kernel/RectorKernel.php @@ -17,7 +17,7 @@ final class RectorKernel /** * @var string */ - private const CACHE_KEY = 'v69'; + private const CACHE_KEY = 'v70'; private ContainerInterface|null $container = null; diff --git a/utils/Command/MissingInSetCommand.php b/utils/Command/MissingInSetCommand.php index 376720008b2..998f59d1bab 100644 --- a/utils/Command/MissingInSetCommand.php +++ b/utils/Command/MissingInSetCommand.php @@ -32,6 +32,20 @@ final class MissingInSetCommand extends Command __DIR__ . '/../../rules/EarlyReturn/Rector' => __DIR__ . '/../../config/set/early-return.php', __DIR__ . '/../../rules/Naming/Rector' => __DIR__ . '/../../config/set/naming.php', __DIR__ . '/../../rules/TypeDeclaration/Rector' => __DIR__ . '/../../config/set/type-declaration.php', + __DIR__ . '/../../rules/Privatization/Rector' => __DIR__ . '/../../config/set/privatization.php', + __DIR__ . '/../../rules/Php52/Rector' => __DIR__ . '/../../config/set/php52.php', + __DIR__ . '/../../rules/Php53/Rector' => __DIR__ . '/../../config/set/php53.php', + __DIR__ . '/../../rules/Php54/Rector' => __DIR__ . '/../../config/set/php54.php', + __DIR__ . '/../../rules/Php55/Rector' => __DIR__ . '/../../config/set/php55.php', + __DIR__ . '/../../rules/Php56/Rector' => __DIR__ . '/../../config/set/php56.php', + __DIR__ . '/../../rules/Php70/Rector' => __DIR__ . '/../../config/set/php70.php', + __DIR__ . '/../../rules/Php71/Rector' => __DIR__ . '/../../config/set/php71.php', + __DIR__ . '/../../rules/Php72/Rector' => __DIR__ . '/../../config/set/php72.php', + __DIR__ . '/../../rules/Php73/Rector' => __DIR__ . '/../../config/set/php73.php', + __DIR__ . '/../../rules/Php74/Rector' => __DIR__ . '/../../config/set/php74.php', + __DIR__ . '/../../rules/Php80/Rector' => __DIR__ . '/../../config/set/php80.php', + __DIR__ . '/../../rules/Php81/Rector' => __DIR__ . '/../../config/set/php81.php', + __DIR__ . '/../../rules/Php82/Rector' => __DIR__ . '/../../config/set/php82.php', ]; /**