Skip to content

Commit d46cc1a

Browse files
authored
Rectify (#7216)
* Rectify * add param
1 parent a72065d commit d46cc1a

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

rules/Php80/Rector/NotIdentical/StrContainsRector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PhpParser\Node\Name;
1717
use PhpParser\Node\Scalar\Int_;
1818
use Rector\Php80\NodeResolver\StrFalseComparisonResolver;
19-
use Rector\PhpParser\Node\Value\ValueResolver;
2019
use Rector\Rector\AbstractRector;
2120
use Rector\ValueObject\PhpVersionFeature;
2221
use Rector\ValueObject\PolyfillPackage;

rules/Php83/Rector/BooleanAnd/JsonValidateRector.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class JsonValidateRector extends AbstractRector implements MinPhpVersionIn
3434

3535
public function __construct(
3636
private readonly BinaryOpManipulator $binaryOpManipulator,
37-
private ValueResolver $valueResolver,
37+
private readonly ValueResolver $valueResolver,
3838
) {
3939
}
4040

@@ -57,7 +57,7 @@ public function getRuleDefinition(): RuleDefinition
5757
,
5858
<<<'CODE_SAMPLE'
5959
if (json_validate($json)) {
60-
}
60+
}
6161
CODE_SAMPLE
6262
),
6363
]
@@ -89,13 +89,14 @@ public function refactor(Node $node): ?Node
8989

9090
$args = $funcCall->getArgs();
9191

92-
if (count($args) < 1 ){
92+
if (count($args) < 1) {
9393
return null;
9494
}
9595

9696
if (! $this->validateArgs($funcCall)) {
9797
return null;
9898
}
99+
99100
$funcCall->name = new Name('json_validate');
100101
$funcCall->args = $args;
101102

@@ -116,8 +117,8 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall
116117

117118
$decodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode(
118119
$booleanAnd->left,
119-
fn ($node) => $node instanceof FuncCall && $this->isName($node->name, 'json_decode'),
120-
fn ($node) => $node instanceof ConstFetch && $this->isName($node->name, 'null')
120+
fn (Node $node): bool => $node instanceof FuncCall && $this->isName($node->name, 'json_decode'),
121+
fn (Node $node): bool => $node instanceof ConstFetch && $this->isName($node->name, 'null')
121122
);
122123

123124
if (! $decodeMatch instanceof TwoNodeMatch) {
@@ -131,23 +132,24 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall
131132

132133
$errorMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode(
133134
$booleanAnd->right,
134-
fn ($node) => $node instanceof FuncCall && $this->isName($node->name, 'json_last_error'),
135-
fn ($node) => $node instanceof ConstFetch && $this->isName($node->name, 'JSON_ERROR_NONE')
135+
fn (Node $node): bool => $node instanceof FuncCall && $this->isName($node->name, 'json_last_error'),
136+
fn (Node $node): bool => $node instanceof ConstFetch && $this->isName($node->name, 'JSON_ERROR_NONE')
136137
);
137138

138139
if (! $errorMatch instanceof TwoNodeMatch) {
139140
return null;
140141
}
141142

142143
// always return the json_decode(...) call
143-
$funcCall = $decodeMatch->getFirstExpr();
144-
if (! $funcCall instanceof FuncCall) {
144+
$expr = $decodeMatch->getFirstExpr();
145+
if (! $expr instanceof FuncCall) {
145146
return null;
146147
}
147-
return $funcCall;
148+
149+
return $expr;
148150
}
149151

150-
protected function validateArgs(FuncCall $funcCall): bool
152+
private function validateArgs(FuncCall $funcCall): bool
151153
{
152154
$depth = $funcCall->getArg('depth', 2);
153155
$flags = $funcCall->getArg('flags', 3);

src/ValueObject/PolyfillPackage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class PolyfillPackage
1313
* @var string
1414
*/
1515
public const PHP_83 = 'symfony/polyfill-php83';
16-
16+
1717
/**
1818
* @var string
1919
*/

0 commit comments

Comments
 (0)