Skip to content

Commit dcfa1a9

Browse files
committed
cs
1 parent 88a7b43 commit dcfa1a9

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use PhpParser\Node\Name\FullyQualified as NameFullyQualified;
1919
use PhpParser\Node\Stmt\Expression;
2020
use PhpParser\Node\Stmt\If_;
21-
use PhpParser\Node\VariadicPlaceholder;
2221
use Rector\DowngradePhp72\NodeManipulator\JsonConstCleaner;
2322
use Rector\Enum\JsonConstant;
2423
use Rector\NodeAnalyzer\DefineFuncCallAnalyzer;
@@ -162,12 +161,16 @@ private function refactorExpression(Expression $expression): ?array
162161
}
163162

164163
// Nothing to do if not a refactored function
165-
if (! in_array($this->getName($funcCall), self::JSON_FUNCTIONS, true)) {
164+
if (! $this->isNames($funcCall, self::JSON_FUNCTIONS)) {
165+
return null;
166+
}
167+
168+
if ($funcCall->isFirstClassCallable()) {
166169
return null;
167170
}
168171

169172
// Nothing to do if the flag `JSON_THROW_ON_ERROR` is not set in args
170-
if (! $this->hasConstFetchInArgs($funcCall->args, 'JSON_THROW_ON_ERROR')) {
173+
if (! $this->hasConstFetchInArgs($funcCall->getArgs(), 'JSON_THROW_ON_ERROR')) {
171174
return null;
172175
}
173176

@@ -194,16 +197,11 @@ private function refactorExpression(Expression $expression): ?array
194197

195198
/**
196199
* Search if a given constant is set within a list of `Arg`
197-
* @param array<Arg|VariadicPlaceholder> $args
200+
* @param Arg[] $args
198201
*/
199202
private function hasConstFetchInArgs(array $args, string $constName): bool
200203
{
201204
foreach ($args as $arg) {
202-
// Only `Arg` instances are handled.
203-
if (! $arg instanceof Arg) {
204-
return false;
205-
}
206-
207205
$value = $arg->value;
208206

209207
if ($value instanceof ConstFetch && $this->getName($value) === $constName) {

0 commit comments

Comments
 (0)