From 6d60cb28b06ab11df4652bb9c84c5c2c2c042c06 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 7 May 2023 20:10:27 +0100 Subject: [PATCH 1/5] [CodeQuality] Remove SimplifyIfExactValueReturnValueRector, as overly defensive --- .../docs/rector_rules_overview.md | 23 +---- config/set/code-quality.php | 2 - .../Fixture/identical_value_compare.php.inc | 31 ------ .../Fixture/multiple_ifs.php.inc | 43 --------- .../Fixture/skip_different_value.php.inc | 15 --- .../Fixture/skip_not_identical.php.inc | 15 --- ...plifyIfExactValueReturnValueRectorTest.php | 28 ------ .../config/configured_rule.php | 10 -- .../Foreach_/ForeachToInArrayRector.php | 2 +- .../SimplifyIfExactValueReturnValueRector.php | 94 ------------------- ...laceEachAssignmentWithKeyCurrentRector.php | 2 +- .../TypedPropertyFromAssignsRector.php | 1 - 12 files changed, 6 insertions(+), 260 deletions(-) delete mode 100644 rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/identical_value_compare.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/multiple_ifs.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/skip_different_value.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/skip_not_identical.php.inc delete mode 100644 rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/SimplifyIfExactValueReturnValueRectorTest.php delete mode 100644 rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/config/configured_rule.php delete mode 100644 rules/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector.php diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index efba29e12a2..bd265566b8a 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 420 Rules Overview +# 419 Rules Overview
@@ -6,7 +6,7 @@ - [Arguments](#arguments) (6) -- [CodeQuality](#codequality) (78) +- [CodeQuality](#codequality) (77) - [CodingStyle](#codingstyle) (39) @@ -1404,23 +1404,6 @@ Changes if/else for same value as assign to ternary
-### SimplifyIfExactValueReturnValueRector - -Changes compared to value and return of expr to direct return - -- class: [`Rector\CodeQuality\Rector\If_\SimplifyIfExactValueReturnValueRector`](../rules/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector.php) - -```diff - $value = 'something'; --if ($value === 52) { -- return 52; --} -- - return $value; -``` - -
- ### SimplifyIfNotNullReturnRector Changes redundant null check to instant return @@ -5398,11 +5381,13 @@ Replace `each()` assign outside loop ```diff $array = ['b' => 1, 'a' => 2]; + -$eachedArray = each($array); +$eachedArray[1] = current($array); +$eachedArray['value'] = current($array); +$eachedArray[0] = key($array); +$eachedArray['key'] = key($array); ++ +next($array); ``` diff --git a/config/set/code-quality.php b/config/set/code-quality.php index f5ea0a2e3d6..19a1bd1869f 100644 --- a/config/set/code-quality.php +++ b/config/set/code-quality.php @@ -62,7 +62,6 @@ use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; -use Rector\CodeQuality\Rector\If_\SimplifyIfExactValueReturnValueRector; use Rector\CodeQuality\Rector\If_\SimplifyIfNotNullReturnRector; use Rector\CodeQuality\Rector\If_\SimplifyIfNullableReturnRector; use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector; @@ -192,7 +191,6 @@ InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, - SimplifyIfExactValueReturnValueRector::class, SimplifyUselessLastVariableAssignRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/identical_value_compare.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/identical_value_compare.php.inc deleted file mode 100644 index 2a8d66069d8..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/identical_value_compare.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/multiple_ifs.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/multiple_ifs.php.inc deleted file mode 100644 index 204b202a41b..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/multiple_ifs.php.inc +++ /dev/null @@ -1,43 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/skip_different_value.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/skip_different_value.php.inc deleted file mode 100644 index 032ec9e2455..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/Fixture/skip_different_value.php.inc +++ /dev/null @@ -1,15 +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/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/config/configured_rule.php deleted file mode 100644 index bcd9d6be0c8..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(SimplifyIfExactValueReturnValueRector::class); -}; diff --git a/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php b/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php index 980c6a2d854..32baeb07284 100644 --- a/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php +++ b/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php @@ -139,7 +139,7 @@ private function shouldSkipForeach(Foreach_ $foreach): bool return true; } - if (!$foreach->stmts[0] instanceof If_) { + if (! $foreach->stmts[0] instanceof If_) { return true; } diff --git a/rules/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector.php b/rules/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector.php deleted file mode 100644 index bbb5ee136f0..00000000000 --- a/rules/CodeQuality/Rector/If_/SimplifyIfExactValueReturnValueRector.php +++ /dev/null @@ -1,94 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [StmtsAwareInterface::class]; - } - - /** - * @param StmtsAwareInterface $node - */ - public function refactor(Node $node): ?StmtsAwareInterface - { - foreach ((array) $node->stmts as $key => $stmt) { - if (! $stmt instanceof If_) { - continue; - } - - // on last stmt already - if (! isset($node->stmts[$key + 1])) { - return null; - } - - $nextNode = $node->stmts[$key + 1]; - if (! $nextNode instanceof Return_) { - continue; - } - - $expr = $this->ifManipulator->matchIfValueReturnValue($stmt); - if (! $expr instanceof Expr) { - return null; - } - - if (! $this->nodeComparator->areNodesEqual($expr, $nextNode->expr)) { - return null; - } - - unset($node->stmts[$key]); - return $node; - } - - return null; - } -} diff --git a/rules/Php72/Rector/Assign/ReplaceEachAssignmentWithKeyCurrentRector.php b/rules/Php72/Rector/Assign/ReplaceEachAssignmentWithKeyCurrentRector.php index 6c71e4974ef..7112c6008e9 100644 --- a/rules/Php72/Rector/Assign/ReplaceEachAssignmentWithKeyCurrentRector.php +++ b/rules/Php72/Rector/Assign/ReplaceEachAssignmentWithKeyCurrentRector.php @@ -126,7 +126,7 @@ private function createNewStmts(Expr $assignVariable, Expr $eachedVariable): arr $this->nodeFactory->createFuncCall('next', [new Arg($eachedVariable)]), ]; - return array_map(static fn(Expr $expr): Expression => new Expression($expr), $exprs); + return array_map(static fn (Expr $expr): Expression => new Expression($expr), $exprs); } private function createDimFetchAssignWithFuncCall( diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php index b763b4212e1..4585888edae 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php @@ -174,5 +174,4 @@ private function decorateTypeWithNullableIfDefaultPropertyNull(Property $propert return TypeCombinator::addNull($inferredType); } - } From 180f398b9f306260e5bd2283d2c891aa352cbdce Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 7 May 2023 20:14:53 +0100 Subject: [PATCH 2/5] [CodingStyle] Remove InlineSimplePropertyAnnotationRector as purely coding standard area --- .../docs/rector_rules_overview.md | 49 +----- ..._var_annotation_with_custom_config.php.inc | 23 --- ...ured_annotation_with_custom_config.php.inc | 12 -- .../EmptyConfig/comment_after_var.php.inc | 13 -- .../inline_simple_var_annotation.php.inc | 23 --- ...e_var_annotation_above_class_const.php.inc | 39 ----- ...ine_simple_var_annotation_combined.php.inc | 23 --- ...simple_var_annotation_with_comment.php.inc | 23 --- .../skip_unconfigured_annotation.php.inc | 12 -- ...ion_with_comment_which_precedes_it.php.inc | 14 -- ..._annotation_with_multiline_comment.php.inc | 13 -- ..._annotation_within_complex_comment.php.inc | 18 -- ...pes_which_break_on_stringification.php.inc | 25 --- ...lineSimplePropertyAnnotationRectorTest.php | 28 ---- ...tyAnnotationWithCustomConfigRectorTest.php | 28 ---- .../config/configure_rule_custom_config.php | 12 -- .../config/configure_rule_empty_config.php | 12 -- .../InlineSimplePropertyAnnotationRector.php | 156 ------------------ .../IfElseInline/config/configured_rule.php | 3 +- 19 files changed, 3 insertions(+), 523 deletions(-) delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/CustomConfig/inline_simple_var_annotation_with_custom_config.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/CustomConfig/skip_unconfigured_annotation_with_custom_config.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/comment_after_var.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_above_class_const.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_combined.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_with_comment.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_unconfigured_annotation.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_comment_which_precedes_it.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_multiline_comment.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_within_complex_comment.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_types_which_break_on_stringification.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationRectorTest.php delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationWithCustomConfigRectorTest.php delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_custom_config.php delete mode 100644 rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_empty_config.php delete mode 100644 rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index bd265566b8a..d31902d9a69 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 419 Rules Overview +# 418 Rules Overview
@@ -8,7 +8,7 @@ - [CodeQuality](#codequality) (77) -- [CodingStyle](#codingstyle) (39) +- [CodingStyle](#codingstyle) (38) - [Compatibility](#compatibility) (1) @@ -2126,51 +2126,6 @@ Refactor `func_get_args()` in to a variadic param
-### InlineSimplePropertyAnnotationRector - -Inline simple `@var` annotations (or other annotations) when they are the only thing in the phpdoc - -:wrench: **configure it!** - -- class: [`Rector\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector`](../rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php) - -```php -ruleWithConfiguration(InlineSimplePropertyAnnotationRector::class, [ - 'var', - 'phpstan-var', - ]); -}; -``` - -↓ - -```diff - final class SomeClass - { -- /** -- * @phpstan-var string -- */ -+ /** @phpstan-var string */ - private const TEXT = 'text'; - -- /** -- * @var DateTime[] -- */ -+ /** @var DateTime[] */ - private ?array $dateTimes; - } -``` - -
- ### MakeInheritedMethodVisibilitySameAsParentRector Make method visibility same as parent one diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/CustomConfig/inline_simple_var_annotation_with_custom_config.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/CustomConfig/inline_simple_var_annotation_with_custom_config.php.inc deleted file mode 100644 index 5fa74113fb4..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/CustomConfig/inline_simple_var_annotation_with_custom_config.php.inc +++ /dev/null @@ -1,23 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/CustomConfig/skip_unconfigured_annotation_with_custom_config.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/CustomConfig/skip_unconfigured_annotation_with_custom_config.php.inc deleted file mode 100644 index 851be1076f2..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/CustomConfig/skip_unconfigured_annotation_with_custom_config.php.inc +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/comment_after_var.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/comment_after_var.php.inc deleted file mode 100644 index 6f8822476e0..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/comment_after_var.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_above_class_const.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_above_class_const.php.inc deleted file mode 100644 index 00c953ac667..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_above_class_const.php.inc +++ /dev/null @@ -1,39 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_combined.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_combined.php.inc deleted file mode 100644 index 44c2be7ed2e..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_combined.php.inc +++ /dev/null @@ -1,23 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_with_comment.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_with_comment.php.inc deleted file mode 100644 index 56d0a87bdd3..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_with_comment.php.inc +++ /dev/null @@ -1,23 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_unconfigured_annotation.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_unconfigured_annotation.php.inc deleted file mode 100644 index 47fd44452b7..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_unconfigured_annotation.php.inc +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_comment_which_precedes_it.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_comment_which_precedes_it.php.inc deleted file mode 100644 index 1691d57ad4c..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_comment_which_precedes_it.php.inc +++ /dev/null @@ -1,14 +0,0 @@ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_multiline_comment.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_multiline_comment.php.inc deleted file mode 100644 index 6b6ca0392cd..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_multiline_comment.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_within_complex_comment.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_within_complex_comment.php.inc deleted file mode 100644 index 9ee16021ef1..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_within_complex_comment.php.inc +++ /dev/null @@ -1,18 +0,0 @@ -") - * @Assert\All({ - * @Assert\NotBlank, - * @AppAssert\Country, - * }) - * @var \DateTime[] $dateTimes - */ - private array $dateTimes; -} -?> diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_types_which_break_on_stringification.php.inc b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_types_which_break_on_stringification.php.inc deleted file mode 100644 index 62ba9c02981..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_var_types_which_break_on_stringification.php.inc +++ /dev/null @@ -1,25 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationRectorTest.php b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationRectorTest.php deleted file mode 100644 index 87e2076c947..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture/EmptyConfig'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configure_rule_empty_config.php'; - } -} diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationWithCustomConfigRectorTest.php b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationWithCustomConfigRectorTest.php deleted file mode 100644 index 9bc93265b76..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationWithCustomConfigRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture/CustomConfig'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configure_rule_custom_config.php'; - } -} diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_custom_config.php b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_custom_config.php deleted file mode 100644 index 52aed52c2d8..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_custom_config.php +++ /dev/null @@ -1,12 +0,0 @@ -ruleWithConfiguration(InlineSimplePropertyAnnotationRector::class, ['custom-var']); -}; diff --git a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_empty_config.php b/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_empty_config.php deleted file mode 100644 index 4d3412069e2..00000000000 --- a/rules-tests/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_empty_config.php +++ /dev/null @@ -1,12 +0,0 @@ -rule(InlineSimplePropertyAnnotationRector::class); -}; diff --git a/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php b/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php deleted file mode 100644 index fbe2d3ed2df..00000000000 --- a/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php +++ /dev/null @@ -1,156 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Property::class, ClassConst::class]; - } - - /** - * @param mixed[] $configuration - */ - public function configure(array $configuration): void - { - Assert::allString($configuration); - - $this->annotationsToConsiderForInlining = array_map( - static fn (string $annotation): string => '@' . ltrim($annotation, '@'), - $configuration - ); - } - - /** - * @param Property|ClassConst $node - */ - public function refactor(Node $node): ?Node - { - if ($this->shouldSkipNode($node)) { - return null; - } - - $comments = $node->getAttribute(AttributeKey::COMMENTS, []); - if ((is_countable($comments) ? count($comments) : 0) !== 1) { - return null; - } - - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); - - if (count($phpDocInfo->getPhpDocNode()->children) > 1) { - return null; - } - - $phpDocNode = $phpDocInfo->getPhpDocNode(); - - $tags = $phpDocNode->getTags(); - if (count($tags) !== 1) { - return null; - } - - // The first value may not be at index 0 - $phpDocTagNode = reset($tags); - - if (! in_array($phpDocTagNode->name, $this->annotationsToConsiderForInlining, true)) { - return null; - } - - if (str_contains((string) $phpDocTagNode, "\n")) { - return null; - } - - // Handle edge cases where stringified tag is not same as it was originally - /** @var Doc $comment */ - $comment = $comments[0]; - if (! str_contains($comment->getText(), (string) $phpDocTagNode)) { - return null; - } - - // Creating new node is the only way to enforce the "singleLined" property AFAIK - $newPhpDocInfo = $this->phpDocInfoFactory->createEmpty($node); - $newPhpDocInfo->makeSingleLined(); - - $newPhpDocNode = $newPhpDocInfo->getPhpDocNode(); - $newPhpDocNode->children = [$phpDocTagNode]; - - return $node; - } - - private function shouldSkipNode(ClassConst|Property $node): bool - { - if ($node instanceof Property && count($node->props) !== 1) { - return true; - } - - return $node instanceof ClassConst && count($node->consts) !== 1; - } -} diff --git a/tests/Issues/IfElseInline/config/configured_rule.php b/tests/Issues/IfElseInline/config/configured_rule.php index 91ee22b2a31..deb910e0eb6 100644 --- a/tests/Issues/IfElseInline/config/configured_rule.php +++ b/tests/Issues/IfElseInline/config/configured_rule.php @@ -3,13 +3,12 @@ declare(strict_types=1); use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; -use Rector\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector; use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->importNames(); + $rectorConfig->rule(SimplifyIfElseToTernaryRector::class); - $rectorConfig->rule(InlineSimplePropertyAnnotationRector::class); $rectorConfig->rule(RemoveUnusedVariableAssignRector::class); }; From 7ac146e4e45bfd7e19a8ee54afe8855d8e3f507e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 7 May 2023 20:19:45 +0100 Subject: [PATCH 3/5] remove deprecated test fixture --- .../IfElseInline/Fixture/fixture.php.inc | 47 ------------------- .../Issues/IfElseInline/IfElseInlineTest.php | 28 ----------- .../IfElseInline/config/configured_rule.php | 14 ------ tests/Issues/Issue6420/Fixture/fixture.php | 13 +++++ 4 files changed, 13 insertions(+), 89 deletions(-) delete mode 100644 tests/Issues/IfElseInline/Fixture/fixture.php.inc delete mode 100644 tests/Issues/IfElseInline/IfElseInlineTest.php delete mode 100644 tests/Issues/IfElseInline/config/configured_rule.php create mode 100644 tests/Issues/Issue6420/Fixture/fixture.php diff --git a/tests/Issues/IfElseInline/Fixture/fixture.php.inc b/tests/Issues/IfElseInline/Fixture/fixture.php.inc deleted file mode 100644 index ddf8bff24e6..00000000000 --- a/tests/Issues/IfElseInline/Fixture/fixture.php.inc +++ /dev/null @@ -1,47 +0,0 @@ - ------ - diff --git a/tests/Issues/IfElseInline/IfElseInlineTest.php b/tests/Issues/IfElseInline/IfElseInlineTest.php deleted file mode 100644 index 60adab60930..00000000000 --- a/tests/Issues/IfElseInline/IfElseInlineTest.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/IfElseInline/config/configured_rule.php b/tests/Issues/IfElseInline/config/configured_rule.php deleted file mode 100644 index deb910e0eb6..00000000000 --- a/tests/Issues/IfElseInline/config/configured_rule.php +++ /dev/null @@ -1,14 +0,0 @@ -importNames(); - - $rectorConfig->rule(SimplifyIfElseToTernaryRector::class); - $rectorConfig->rule(RemoveUnusedVariableAssignRector::class); -}; diff --git a/tests/Issues/Issue6420/Fixture/fixture.php b/tests/Issues/Issue6420/Fixture/fixture.php new file mode 100644 index 00000000000..a691fe8eb64 --- /dev/null +++ b/tests/Issues/Issue6420/Fixture/fixture.php @@ -0,0 +1,13 @@ + From 7fc734a1ae18a8a1bbb99d0841da5c8d541153b6 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 7 May 2023 20:20:19 +0100 Subject: [PATCH 4/5] remove unused makeSinglelined() --- packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php index 2ff6ec71adf..5786a101e59 100644 --- a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php +++ b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php @@ -330,11 +330,6 @@ public function isNewNode(): bool return $this->betterTokenIterator->count() === 0; } - public function makeSingleLined(): void - { - $this->isSingleLine = true; - } - public function isSingleLine(): bool { return $this->isSingleLine; From 3852ae2cbc6f960b43ae7bfc1db375a9c0a94ccb Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 7 May 2023 20:20:37 +0100 Subject: [PATCH 5/5] remove unused match if return value method --- .../Foreach_/ForeachToInArrayRector.php | 5 +-- src/NodeManipulator/IfManipulator.php | 38 ------------------- tests/Issues/Issue6420/Fixture/fixture.php | 13 ------- 3 files changed, 1 insertion(+), 55 deletions(-) delete mode 100644 tests/Issues/Issue6420/Fixture/fixture.php diff --git a/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php b/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php index 32baeb07284..51cd93fdfbc 100644 --- a/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php +++ b/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php @@ -162,11 +162,8 @@ private function shouldSkipForeach(Foreach_ $foreach): bool } $foreachValueStaticType = $this->getType($foreach->expr); - if ($foreachValueStaticType instanceof ObjectType) { - return true; - } - return false; + return $foreachValueStaticType instanceof ObjectType; } private function shouldSkipIf(If_ $if): bool diff --git a/src/NodeManipulator/IfManipulator.php b/src/NodeManipulator/IfManipulator.php index 97af3bae06c..89b4f2befa0 100644 --- a/src/NodeManipulator/IfManipulator.php +++ b/src/NodeManipulator/IfManipulator.php @@ -7,7 +7,6 @@ use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Assign; -use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\Exit_; use PhpParser\Node\Expr\Variable; @@ -57,43 +56,6 @@ public function matchIfNotNullReturnValue(If_ $if): ?Expr return $this->matchComparedAndReturnedNode($if->cond, $insideIfNode); } - /** - * Matches: - * - * if (<$value> === null) { - * return null; - * } - * - * if (<$value> === 53;) { - * return 53; - * } - */ - public function matchIfValueReturnValue(If_ $if): ?Expr - { - if (count($if->stmts) !== 1) { - return null; - } - - $insideIfStmt = $if->stmts[0]; - if (! $insideIfStmt instanceof Return_) { - return null; - } - - if (! $if->cond instanceof Identical) { - return null; - } - - if ($this->nodeComparator->areNodesEqual($if->cond->left, $insideIfStmt->expr)) { - return $if->cond->right; - } - - if ($this->nodeComparator->areNodesEqual($if->cond->right, $insideIfStmt->expr)) { - return $if->cond->left; - } - - return null; - } - /** * @return If_[] */ diff --git a/tests/Issues/Issue6420/Fixture/fixture.php b/tests/Issues/Issue6420/Fixture/fixture.php deleted file mode 100644 index a691fe8eb64..00000000000 --- a/tests/Issues/Issue6420/Fixture/fixture.php +++ /dev/null @@ -1,13 +0,0 @@ -