From ea36bcf4ebcb667779088065a95907a36043b12a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 19 Dec 2025 23:18:12 +0100 Subject: [PATCH 1/2] cleanup --- README.md | 8 +--- .../DowngradePhp73JsonConstRector.php | 41 ++++++++----------- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 613d02cb..6bc9b85b 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,10 @@ composer require rector/rector --dev To add a set to your config, use `Rector\Set\ValueObject\DowngradeLevelSetList` class and pick target set: ```php -use Rector\Set\ValueObject\DowngradeLevelSetList; use Rector\Config\RectorConfig; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->sets([ - DowngradeLevelSetList::DOWN_TO_PHP_72 - ]); -}; +return RectorConfig::configure() + ->withDowngradeSets(php72: true); ``` Then run Rector to downgrade your code to PHP 7.2! diff --git a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php index 184b873b..106ebd65 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -102,13 +102,8 @@ public function refactor(Node $node): null|Expr|array return null; } - // if ($node instanceof TryCatch) { - // SimpleNodeTraverser::decorateWithAttributeValue($node->stmts, self::IS_EXPRESSION_INSIDE_TRY_CATCH, true); - // return null; - // } - if ($node instanceof Expression) { - return $this->refactorStmt($node); + return $this->refactorExpression($node); } return $this->jsonConstCleaner->clean($node, [JsonConstant::THROW_ON_ERROR]); @@ -154,14 +149,14 @@ private function resolveFuncCall(Expression $Expression): ?FuncCall * * @return null|array */ - private function refactorStmt(Expression $Expression): ?array + private function refactorExpression(Expression $expression): ?array { - if ($Expression->getAttribute(AttributeKey::IS_IN_TRY_BLOCK) === true) { + if ($expression->getAttribute(AttributeKey::IS_IN_TRY_BLOCK) === true) { return null; } // retrieve a `FuncCall`, if any, from the statement - $funcCall = $this->resolveFuncCall($Expression); + $funcCall = $this->resolveFuncCall($expression); // Nothing to do if no `FuncCall` found if (! $funcCall instanceof FuncCall) { @@ -178,7 +173,7 @@ private function refactorStmt(Expression $Expression): ?array return null; } - $nodes = [$Expression]; + $nodes = [$expression]; $nodes[] = new If_( new NotIdentical( new FuncCall(new Name('json_last_error')), @@ -228,26 +223,22 @@ private function hasConstFetchInArgs(array $args, string $constName): bool /** * Search if a given constant is set within a `BitwiseOr` */ - private function hasConstFetchInBitwiseOr(BitwiseOr $bitwiseOr, string $constName): bool + private function hasConstFetchInBitwiseOr(BitwiseOr $bitwiseOr, string $constantName): bool { - $found = false; - foreach ([$bitwiseOr->left, $bitwiseOr->right] as $subNode) { - $found = match (true) { - $subNode instanceof BitwiseOr => ( - $this->hasConstFetchInBitwiseOr($subNode, $constName) - ), - $subNode instanceof ConstFetch => ( - $this->getName($subNode) === $constName - ), - default => false - }; + if ($subNode instanceof BitwiseOr) { + if ($this->hasConstFetchInBitwiseOr($subNode, $constantName)) { + return true; + } + } - if ($found) { - break; + if ($subNode instanceof ConstFetch) { + if ($this->isName($subNode, $constantName)) { + return true; + } } } - return $found; + return false; } } From 8cc2b8ad3c317a933d2ce7799a3bf54293b234d5 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 19 Dec 2025 22:21:22 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- .../ConstFetch/DowngradePhp73JsonConstRector.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php index 106ebd65..2d4fbb27 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -226,16 +226,12 @@ private function hasConstFetchInArgs(array $args, string $constName): bool private function hasConstFetchInBitwiseOr(BitwiseOr $bitwiseOr, string $constantName): bool { foreach ([$bitwiseOr->left, $bitwiseOr->right] as $subNode) { - if ($subNode instanceof BitwiseOr) { - if ($this->hasConstFetchInBitwiseOr($subNode, $constantName)) { - return true; - } + if ($subNode instanceof BitwiseOr && $this->hasConstFetchInBitwiseOr($subNode, $constantName)) { + return true; } - if ($subNode instanceof ConstFetch) { - if ($this->isName($subNode, $constantName)) { - return true; - } + if ($subNode instanceof ConstFetch && $this->isName($subNode, $constantName)) { + return true; } }