diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index 4652f74a873..e4f7debb807 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 369 Rules Overview +# 368 Rules Overview
@@ -8,7 +8,7 @@ - [CodeQuality](#codequality) (72) -- [CodingStyle](#codingstyle) (32) +- [CodingStyle](#codingstyle) (31) - [DeadCode](#deadcode) (43) @@ -2299,24 +2299,6 @@ Use ++ increment instead of `$var += 1`
-### VarConstantCommentRector - -Constant should have a `@var` comment with type - -- class: [`Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector`](../rules/CodingStyle/Rector/ClassConst/VarConstantCommentRector.php) - -```diff - class SomeClass - { -+ /** -+ * @var string -+ */ - const HI = 'hi'; - } -``` - -
- ### VersionCompareFuncCallToConstantRector Changes use of call to version compare function to use of PHP version constant diff --git a/config/set/coding-style.php b/config/set/coding-style.php index 674e7d591e9..beeffe9e8a0 100644 --- a/config/set/coding-style.php +++ b/config/set/coding-style.php @@ -8,7 +8,6 @@ use Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector; use Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector; use Rector\CodingStyle\Rector\ClassConst\SplitGroupedClassConstantsRector; -use Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector; use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector; @@ -59,7 +58,6 @@ CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, - VarConstantCommentRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, diff --git a/phpstan.neon b/phpstan.neon index 6d0f23416bb..4f199fdc207 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -683,8 +683,3 @@ parameters: # for symfony configs check - '#Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\tagged_iterator not found#' - - - """ - #^Fetching class constant class of deprecated class Rector\\\\CodingStyle\\\\Rector\\\\ClassConst\\\\VarConstantCommentRector\\: - The doc block types are not reliable, and typed constants are comming to PHP 8\\.3, use those instead\\.$# - """ diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/arrays.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/arrays.php.inc deleted file mode 100644 index b2eff7482c7..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/arrays.php.inc +++ /dev/null @@ -1,52 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/explicit_key_array.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/explicit_key_array.php.inc deleted file mode 100644 index 66e9ca2002a..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/explicit_key_array.php.inc +++ /dev/null @@ -1,39 +0,0 @@ - 'hi' - ]; - - const VALUES_WITHOUT_KEYS = [ - 'hi' - ]; -} - -?> ------ - 'hi' - ]; - - /** - * @var string[] - */ - const VALUES_WITHOUT_KEYS = [ - 'hi' - ]; -} - -?> diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/fixture.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/fixture.php.inc deleted file mode 100644 index cb7c79a6d5d..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,24 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/keep_class_string_key.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/keep_class_string_key.php.inc deleted file mode 100644 index c1614a1e121..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/keep_class_string_key.php.inc +++ /dev/null @@ -1,20 +0,0 @@ -, string> - */ - private const TAGS_TYPES_TO_NAMES = [ - ReturnTagValueNode::class => '@return', - ParamTagValueNode::class => '@param', - VarTagValueNode::class => '@var', - ]; -} diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/misc_type.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/misc_type.php.inc deleted file mode 100644 index 0a3cf9ab561..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/misc_type.php.inc +++ /dev/null @@ -1,43 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/no_slash.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/no_slash.php.inc deleted file mode 100644 index 050b63cc161..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/no_slash.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/pair_class_string_array.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/pair_class_string_array.php.inc deleted file mode 100644 index 3cc80b8108b..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/pair_class_string_array.php.inc +++ /dev/null @@ -1,28 +0,0 @@ - PairClassStringArray::class, - ]; -} - -?> ------ -> - */ - private const CLASSES = [ - \stdClass::class => PairClassStringArray::class, - ]; -} - -?> diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/pair_class_string_array_too_many.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/pair_class_string_array_too_many.php.inc deleted file mode 100644 index 9fdd4cfefce..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/pair_class_string_array_too_many.php.inc +++ /dev/null @@ -1,52 +0,0 @@ - Aa::class, - B::class => Bb::class, - C::class => Cc::class, - D::class => Dd::class, - ]; -} - -?> ------ - - */ - private const CLASSES = [ - A::class => Aa::class, - B::class => Bb::class, - C::class => Cc::class, - D::class => Dd::class, - ]; -} - -?> diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_already_constant_string.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_already_constant_string.php.inc deleted file mode 100644 index 214664f7348..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_already_constant_string.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - package-name - * - "[aliased-package-name] "Message => aliased-package-name - * - "[Aliased\PackageName] "Message => Aliased\PackageName - */ - public const PACKAGE_NAME_PATTERN = '#\[(?[-\w\\\\]+)\]( ){1,}#'; -} diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_class_string_key_value.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_class_string_key_value.php.inc deleted file mode 100644 index 1e3118a8f65..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_class_string_key_value.php.inc +++ /dev/null @@ -1,20 +0,0 @@ -, array>> - */ - public const PRIORITY_TYPES = [ - BinaryOp::class => [BinaryOp::class, Expr::class], - ]; -} diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_doule_class_string.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_doule_class_string.php.inc deleted file mode 100644 index 5322d1abb08..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_doule_class_string.php.inc +++ /dev/null @@ -1,14 +0,0 @@ - - */ - private const ALLOWED_CLASS_TYPES = [Strings::class, TrinaryLogic::class]; -} diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_mixed.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_mixed.php.inc deleted file mode 100644 index dd5ff07d611..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_mixed.php.inc +++ /dev/null @@ -1,25 +0,0 @@ - [ - 'phpunit/phpunit' => 'v1.0.0', - 'rector/rector' => 'v1.0.0', - ], - 'autoload-dev' => [ - 'psr-4' => [ - 'Symplify\Tests\\' => 'tests', - 'Symplify\SuperTests\\' => 'super-tests', - ], - 'files' => ['src/SomeFile.php', 'src/KeepFile.php'], - ], - ]; -} diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_negative_int_over_int.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_negative_int_over_int.php.inc deleted file mode 100644 index 741455bdda3..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/skip_negative_int_over_int.php.inc +++ /dev/null @@ -1,9 +0,0 @@ -|string>> - */ - private const CONFLICTING_CHECKER_GROUPS = [ - ['SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff', YodaStyleFixer::class], - [LowerCaseConstantSniff::class, UpperCaseConstantSniff::class], - [LowercaseConstantsFixer::class, UpperCaseConstantSniff::class], - [ConstantCaseFixer::class, UpperCaseConstantSniff::class], - ['SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff', DeclareEqualNormalizeFixer::class], - ['SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff', BlankLineAfterOpeningTagFixer::class], - [FileHeaderSniff::class, NoBlankLinesAfterPhpdocFixer::class], - ]; -} diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/union_const.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/union_const.php.inc deleted file mode 100644 index b5c55ef4d3a..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/union_const.php.inc +++ /dev/null @@ -1,39 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/union_nested_and_single_level_array_scalars.php.inc b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/union_nested_and_single_level_array_scalars.php.inc deleted file mode 100644 index 99f6c09bc54..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/Fixture/union_nested_and_single_level_array_scalars.php.inc +++ /dev/null @@ -1,34 +0,0 @@ - ['value2', 1234], - 1 => null, - ]; -} - -?> ------ - - */ - public const ARRAY_CONST = [ - 'key2' => ['value2', 1234], - 1 => null, - ]; -} - -?> diff --git a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/VarConstantCommentRectorTest.php b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/VarConstantCommentRectorTest.php deleted file mode 100644 index 594dde09b14..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/VarConstantCommentRectorTest.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/CodingStyle/Rector/ClassConst/VarConstantCommentRector/config/configured_rule.php b/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/config/configured_rule.php deleted file mode 100644 index fe2754aa6e2..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassConst/VarConstantCommentRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(VarConstantCommentRector::class); -}; diff --git a/rules/CodingStyle/Rector/ClassConst/VarConstantCommentRector.php b/rules/CodingStyle/Rector/ClassConst/VarConstantCommentRector.php deleted file mode 100644 index 945de157d06..00000000000 --- a/rules/CodingStyle/Rector/ClassConst/VarConstantCommentRector.php +++ /dev/null @@ -1,169 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [ClassConst::class]; - } - - /** - * @param ClassConst $node - */ - public function refactor(Node $node): ?Node - { - if (count($node->consts) > 1) { - return null; - } - - $constType = $this->getType($node->consts[0]->value); - if ($constType instanceof MixedType) { - return null; - } - - // generalize false/true type to bool, as mostly default value but accepts both - $constType = $this->typeNormalizer->generalizeConstantBoolTypes($constType); - - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); - if ($this->shouldSkipConstantArrayType($constType, $phpDocInfo)) { - return null; - } - - if ($this->typeComparator->isSubtype($constType, $phpDocInfo->getVarType())) { - return null; - } - - // already filled - if ($phpDocInfo->getVarTagValueNode() instanceof VarTagValueNode) { - return null; - } - - $this->phpDocTypeChanger->changeVarType($node, $phpDocInfo, $constType); - if (! $phpDocInfo->hasChanged()) { - return null; - } - - return $node; - } - - private function hasTwoAndMoreGenericClassStringTypes(ConstantArrayType $constantArrayType): bool - { - $typeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($constantArrayType); - if (! $typeNode instanceof ArrayTypeNode) { - return false; - } - - if (! $typeNode->type instanceof UnionTypeNode) { - return false; - } - - $genericTypeNodeCount = 0; - foreach ($typeNode->type->types as $unionedTypeNode) { - if ($unionedTypeNode instanceof GenericTypeNode) { - ++$genericTypeNodeCount; - } - } - - return $genericTypeNodeCount > 1; - } - - /** - * Skip big arrays and mixed[] constants - */ - private function shouldSkipConstantArrayType(Type $constType, PhpDocInfo $phpDocInfo): bool - { - if (! $constType instanceof ConstantArrayType) { - return false; - } - - $currentVarType = $phpDocInfo->getVarType(); - if ($currentVarType instanceof ArrayType && $currentVarType->getItemType() instanceof MixedType) { - return true; - } - - if ($this->hasTwoAndMoreGenericClassStringTypes($constType)) { - return true; - } - - return $this->isHugeNestedConstantArrayTyp($constType); - } - - private function isHugeNestedConstantArrayTyp(ConstantArrayType $constantArrayType): bool - { - if (count($constantArrayType->getValueTypes()) <= 3) { - return false; - } - - foreach ($constantArrayType->getValueTypes() as $constValueType) { - if ($constValueType instanceof ConstantArrayType) { - return true; - } - } - - return false; - } -} diff --git a/tests/Issues/IssueVarConstantNewline/Fixture/fixture.php.inc b/tests/Issues/IssueVarConstantNewline/Fixture/fixture.php.inc deleted file mode 100644 index cc077a05c44..00000000000 --- a/tests/Issues/IssueVarConstantNewline/Fixture/fixture.php.inc +++ /dev/null @@ -1,52 +0,0 @@ - ------ - diff --git a/tests/Issues/IssueVarConstantNewline/IssueVarConstantNewlineTest.php b/tests/Issues/IssueVarConstantNewline/IssueVarConstantNewlineTest.php deleted file mode 100644 index 78ea6d2a120..00000000000 --- a/tests/Issues/IssueVarConstantNewline/IssueVarConstantNewlineTest.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/tests/Issues/IssueVarConstantNewline/config/configured_rule.php b/tests/Issues/IssueVarConstantNewline/config/configured_rule.php deleted file mode 100644 index 0a3b9b94b3b..00000000000 --- a/tests/Issues/IssueVarConstantNewline/config/configured_rule.php +++ /dev/null @@ -1,12 +0,0 @@ -rule(VarConstantCommentRector::class); - $rectorConfig->rule(NewlineAfterStatementRector::class); -};