From ba0fbf7b68e3a5ef2553d5c880460bc854f9a9c8 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 4 Jun 2023 23:30:18 +0200 Subject: [PATCH 1/3] remove deprecated UnionTypesRector, use exact type declaration rules instead --- .../docs/rector_rules_overview.md | 26 +----- phpstan.neon | 1 - .../Rector/FunctionLike/UnionTypesRector.php | 82 ------------------- 3 files changed, 2 insertions(+), 107 deletions(-) delete mode 100644 rules/Php80/Rector/FunctionLike/UnionTypesRector.php diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index 93a9b040379..1ff9e1b0196 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 389 Rules Overview +# 387 Rules Overview
@@ -42,7 +42,7 @@ - [Php74](#php74) (13) -- [Php80](#php80) (19) +- [Php80](#php80) (18) - [Php81](#php81) (12) @@ -5894,28 +5894,6 @@ Add `Stringable` interface to classes with `__toString()` method
-### UnionTypesRector - -Change docs types to union types, where possible (properties are covered by TypedPropertiesRector) - -- class: [`Rector\Php80\Rector\FunctionLike\UnionTypesRector`](../rules/Php80/Rector/FunctionLike/UnionTypesRector.php) - -```diff - class SomeClass - { -- /** -- * @param array|int $number -- * @return bool|float -- */ -- public function go($number) -+ public function go(array|int $number): bool|float - { - } - } -``` - -
- ## Php81 ### ConstantListClassToEnumRector diff --git a/phpstan.neon b/phpstan.neon index 2900121c47e..1a5ecfe736b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -697,7 +697,6 @@ parameters: - '#Property Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts \(array\|null\) does not accept array#' # deprecated - - '#Register "Rector\\Php80\\Rector\\FunctionLike\\UnionTypesRector" service to "php80\.php" config set#' - '#Fetching class constant class of deprecated class Rector\\CodeQuality\\Rector\\ClassMethod\\NarrowUnionTypeDocRector#' diff --git a/rules/Php80/Rector/FunctionLike/UnionTypesRector.php b/rules/Php80/Rector/FunctionLike/UnionTypesRector.php deleted file mode 100644 index bfc10f2b81d..00000000000 --- a/rules/Php80/Rector/FunctionLike/UnionTypesRector.php +++ /dev/null @@ -1,82 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [ClassMethod::class, Function_::class, Closure::class, ArrowFunction::class]; - } - - /** - * @param ClassMethod|Function_|Closure|ArrowFunction $node - */ - public function refactor(Node $node): ?Node - { - $errorMessage = sprintf( - 'Rule "%s" is deprecated, as dangerous to move docblocks for type declarations. Use strict type rules instead', - self::class - ); - trigger_error($errorMessage, E_USER_WARNING); - sleep(3); - - return null; - } - - public function provideMinPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES; - } -} From 30ca175a3f5abb30d45ac9c97414c9772e1f2d68 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 4 Jun 2023 23:30:55 +0200 Subject: [PATCH 2/3] remove is arg in position methods --- src/NodeAnalyzer/ArgsAnalyzer.php | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/NodeAnalyzer/ArgsAnalyzer.php b/src/NodeAnalyzer/ArgsAnalyzer.php index 1416ca17735..de88e9af6a7 100644 --- a/src/NodeAnalyzer/ArgsAnalyzer.php +++ b/src/NodeAnalyzer/ArgsAnalyzer.php @@ -9,33 +9,6 @@ final class ArgsAnalyzer { - /** - * @api - * @deprecated Use $node->getArgs()[x] instead - * @param Arg[] $args - */ - public function isArgInstanceInArgsPosition(array $args, int $position): bool - { - return isset($args[$position]); - } - - /** - * @api - * @param Arg[] $args - * @param int[] $positions - * @deprecated use count($node->getArgs() < X instead - */ - public function isArgsInstanceInArgsPositions(array $args, array $positions): bool - { - foreach ($positions as $position) { - if (! isset($args[$position])) { - return false; - } - } - - return true; - } - /** * @param mixed[]|Arg[] $args */ From c7a0b5fd19376e45eb1e7bcc008ca1fe0f16aaa3 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 4 Jun 2023 23:32:10 +0200 Subject: [PATCH 3/3] remove drepcated NarrowUnionTypeDocRector --- .../docs/rector_rules_overview.md | 24 +------ phpstan.neon | 3 - .../ClassMethod/NarrowUnionTypeDocRector.php | 69 ------------------- utils/Command/MissingInSetCommand.php | 3 - 4 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 rules/CodeQuality/Rector/ClassMethod/NarrowUnionTypeDocRector.php diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index 1ff9e1b0196..51abf140cdf 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 387 Rules Overview +# 386 Rules Overview
@@ -6,7 +6,7 @@ - [Arguments](#arguments) (6) -- [CodeQuality](#codequality) (73) +- [CodeQuality](#codequality) (72) - [CodingStyle](#codingstyle) (34) @@ -1018,26 +1018,6 @@ Change OR, AND to ||, && with more common understanding
-### NarrowUnionTypeDocRector - -Changes docblock by narrowing type - -- class: [`Rector\CodeQuality\Rector\ClassMethod\NarrowUnionTypeDocRector`](../rules/CodeQuality/Rector/ClassMethod/NarrowUnionTypeDocRector.php) - -```diff - class SomeClass { - /** -- * @param object|DateTime $message -+ * @param DateTime $message - */ - public function getMessage(object $message) - { - } - } -``` - -
- ### NewStaticToNewSelfRector Change unsafe new `static()` to new `self()` diff --git a/phpstan.neon b/phpstan.neon index 1a5ecfe736b..7ea4e5c7bbd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -696,9 +696,6 @@ parameters: # resolve continually - '#Property Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts \(array\|null\) does not accept array#' - # deprecated - - '#Fetching class constant class of deprecated class Rector\\CodeQuality\\Rector\\ClassMethod\\NarrowUnionTypeDocRector#' - # statics are required in the kernel for performance reasons - diff --git a/rules/CodeQuality/Rector/ClassMethod/NarrowUnionTypeDocRector.php b/rules/CodeQuality/Rector/ClassMethod/NarrowUnionTypeDocRector.php deleted file mode 100644 index 9aa59e4b238..00000000000 --- a/rules/CodeQuality/Rector/ClassMethod/NarrowUnionTypeDocRector.php +++ /dev/null @@ -1,69 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [ClassMethod::class]; - } - - /** - * @param ClassMethod $node - */ - public function refactor(Node $node): ?Node - { - $errorMessage = sprintf( - 'Rule "%s" is deprecated, as we moved from docblocks for type declarations. Use strict type rules instead', - self::class - ); - trigger_error($errorMessage, E_USER_WARNING); - sleep(3); - - return null; - } -} diff --git a/utils/Command/MissingInSetCommand.php b/utils/Command/MissingInSetCommand.php index 6b7a1f62c7e..563d3dfe99a 100644 --- a/utils/Command/MissingInSetCommand.php +++ b/utils/Command/MissingInSetCommand.php @@ -6,7 +6,6 @@ use Nette\Utils\Strings; use Rector\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector; -use Rector\CodeQuality\Rector\ClassMethod\NarrowUnionTypeDocRector; use Rector\CodingStyle\Rector\ClassMethod\DataProviderArrayItemsNewlinedRector; use Rector\CodingStyle\Rector\Property\NullifyUnionNullableRector; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; @@ -52,8 +51,6 @@ final class MissingInSetCommand extends Command FlipNegatedTernaryInstanceofRector::class, BinaryOpNullableToInstanceofRector::class, WhileNullableToInstanceofRector::class, - // deprecated - NarrowUnionTypeDocRector::class, ]; public function __construct(