From accc164e5bf1562251d84c4c628d21eca7db5ab3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 4 Sep 2025 21:06:49 +0700 Subject: [PATCH 1/2] Rectify --- .../Rector/NotIdentical/StrContainsRector.php | 1 - .../Rector/BooleanAnd/JsonValidateRector.php | 22 ++++++++++--------- src/ValueObject/PolyfillPackage.php | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/rules/Php80/Rector/NotIdentical/StrContainsRector.php b/rules/Php80/Rector/NotIdentical/StrContainsRector.php index 3d3f3710bf6..e226fb15d7e 100644 --- a/rules/Php80/Rector/NotIdentical/StrContainsRector.php +++ b/rules/Php80/Rector/NotIdentical/StrContainsRector.php @@ -16,7 +16,6 @@ use PhpParser\Node\Name; use PhpParser\Node\Scalar\Int_; use Rector\Php80\NodeResolver\StrFalseComparisonResolver; -use Rector\PhpParser\Node\Value\ValueResolver; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\ValueObject\PolyfillPackage; diff --git a/rules/Php83/Rector/BooleanAnd/JsonValidateRector.php b/rules/Php83/Rector/BooleanAnd/JsonValidateRector.php index eea87297052..7bd12908722 100644 --- a/rules/Php83/Rector/BooleanAnd/JsonValidateRector.php +++ b/rules/Php83/Rector/BooleanAnd/JsonValidateRector.php @@ -34,7 +34,7 @@ final class JsonValidateRector extends AbstractRector implements MinPhpVersionIn public function __construct( private readonly BinaryOpManipulator $binaryOpManipulator, - private ValueResolver $valueResolver, + private readonly ValueResolver $valueResolver, ) { } @@ -89,13 +89,14 @@ public function refactor(Node $node): ?Node $args = $funcCall->getArgs(); - if (count($args) < 1 ){ + if (count($args) < 1) { return null; } if (! $this->validateArgs($funcCall)) { return null; } + $funcCall->name = new Name('json_validate'); $funcCall->args = $args; @@ -116,8 +117,8 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall $decodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $booleanAnd->left, - fn ($node) => $node instanceof FuncCall && $this->isName($node->name, 'json_decode'), - fn ($node) => $node instanceof ConstFetch && $this->isName($node->name, 'null') + fn ($node): bool => $node instanceof FuncCall && $this->isName($node->name, 'json_decode'), + fn ($node): bool => $node instanceof ConstFetch && $this->isName($node->name, 'null') ); if (! $decodeMatch instanceof TwoNodeMatch) { @@ -131,8 +132,8 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall $errorMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $booleanAnd->right, - fn ($node) => $node instanceof FuncCall && $this->isName($node->name, 'json_last_error'), - fn ($node) => $node instanceof ConstFetch && $this->isName($node->name, 'JSON_ERROR_NONE') + fn ($node): bool => $node instanceof FuncCall && $this->isName($node->name, 'json_last_error'), + fn ($node): bool => $node instanceof ConstFetch && $this->isName($node->name, 'JSON_ERROR_NONE') ); if (! $errorMatch instanceof TwoNodeMatch) { @@ -140,14 +141,15 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall } // always return the json_decode(...) call - $funcCall = $decodeMatch->getFirstExpr(); - if (! $funcCall instanceof FuncCall) { + $expr = $decodeMatch->getFirstExpr(); + if (! $expr instanceof FuncCall) { return null; } - return $funcCall; + + return $expr; } - protected function validateArgs(FuncCall $funcCall): bool + private function validateArgs(FuncCall $funcCall): bool { $depth = $funcCall->getArg('depth', 2); $flags = $funcCall->getArg('flags', 3); diff --git a/src/ValueObject/PolyfillPackage.php b/src/ValueObject/PolyfillPackage.php index dd9c1e0d8a1..a3772b256ab 100644 --- a/src/ValueObject/PolyfillPackage.php +++ b/src/ValueObject/PolyfillPackage.php @@ -13,7 +13,7 @@ final class PolyfillPackage * @var string */ public const PHP_83 = 'symfony/polyfill-php83'; - + /** * @var string */ From 0fb8ab1622d512efdfb4215d4f4b253f44458ead Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 4 Sep 2025 21:08:29 +0700 Subject: [PATCH 2/2] add param --- rules/Php83/Rector/BooleanAnd/JsonValidateRector.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rules/Php83/Rector/BooleanAnd/JsonValidateRector.php b/rules/Php83/Rector/BooleanAnd/JsonValidateRector.php index 7bd12908722..b31db24c211 100644 --- a/rules/Php83/Rector/BooleanAnd/JsonValidateRector.php +++ b/rules/Php83/Rector/BooleanAnd/JsonValidateRector.php @@ -57,7 +57,7 @@ public function getRuleDefinition(): RuleDefinition , <<<'CODE_SAMPLE' if (json_validate($json)) { -} +} CODE_SAMPLE ), ] @@ -117,8 +117,8 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall $decodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $booleanAnd->left, - fn ($node): bool => $node instanceof FuncCall && $this->isName($node->name, 'json_decode'), - fn ($node): bool => $node instanceof ConstFetch && $this->isName($node->name, 'null') + fn (Node $node): bool => $node instanceof FuncCall && $this->isName($node->name, 'json_decode'), + fn (Node $node): bool => $node instanceof ConstFetch && $this->isName($node->name, 'null') ); if (! $decodeMatch instanceof TwoNodeMatch) { @@ -132,8 +132,8 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall $errorMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $booleanAnd->right, - fn ($node): bool => $node instanceof FuncCall && $this->isName($node->name, 'json_last_error'), - fn ($node): bool => $node instanceof ConstFetch && $this->isName($node->name, 'JSON_ERROR_NONE') + fn (Node $node): bool => $node instanceof FuncCall && $this->isName($node->name, 'json_last_error'), + fn (Node $node): bool => $node instanceof ConstFetch && $this->isName($node->name, 'JSON_ERROR_NONE') ); if (! $errorMatch instanceof TwoNodeMatch) {