Skip to content

Commit 4bf5dfd

Browse files
committed
misc
1 parent ab3a60e commit 4bf5dfd

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ includes:
55
parameters:
66
level: 8
77
errorFormat: symplify
8-
# reportUnmatchedIgnoredErrors: false
8+
reportUnmatchedIgnoredErrors: false
99

1010
# see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases
1111
typeAliases:

rules-tests/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector/Fixture/class_is_nullable.php

Whitespace-only changes.

rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php

Lines changed: 9 additions & 15 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;
@@ -119,9 +118,9 @@ private function markConstantKnownInInnerStmts(If_ $if): void
119118
SimpleNodeTraverser::decorateWithAttributeValue($if, self::PHP73_JSON_CONSTANT_IS_KNOWN, true);
120119
}
121120

122-
private function resolveFuncCall(Expression $Expression): ?FuncCall
121+
private function resolveFuncCall(Expression $expression): ?FuncCall
123122
{
124-
$expr = $Expression->expr;
123+
$expr = $expression->expr;
125124
if ($expr instanceof Assign) {
126125
if ($expr->expr instanceof FuncCall) {
127126
return $expr->expr;
@@ -153,21 +152,22 @@ private function refactorExpression(Expression $expression): ?array
153152
return null;
154153
}
155154

156-
// retrieve a `FuncCall`, if any, from the statement
157155
$funcCall = $this->resolveFuncCall($expression);
158-
159-
// Nothing to do if no `FuncCall` found
160156
if (! $funcCall instanceof FuncCall) {
161157
return null;
162158
}
163159

160+
if ($funcCall->isFirstClassCallable()) {
161+
return null;
162+
}
163+
164164
// Nothing to do if not a refactored function
165-
if (! in_array($this->getName($funcCall), self::JSON_FUNCTIONS, true)) {
165+
if (! $this->isNames($funcCall, self::JSON_FUNCTIONS)) {
166166
return null;
167167
}
168168

169169
// 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')) {
170+
if (! $this->hasConstFetchInArgs($funcCall->getArgs(), 'JSON_THROW_ON_ERROR')) {
171171
return null;
172172
}
173173

@@ -194,18 +194,12 @@ private function refactorExpression(Expression $expression): ?array
194194

195195
/**
196196
* Search if a given constant is set within a list of `Arg`
197-
* @param array<Arg|VariadicPlaceholder> $args
197+
* @param Arg[] $args
198198
*/
199199
private function hasConstFetchInArgs(array $args, string $constName): bool
200200
{
201201
foreach ($args as $arg) {
202-
// Only `Arg` instances are handled.
203-
if (! $arg instanceof Arg) {
204-
return false;
205-
}
206-
207202
$value = $arg->value;
208-
209203
if ($value instanceof ConstFetch && $this->getName($value) === $constName) {
210204
return true;
211205
}

tests/Issues/DowngradeNullJson/Fixture/fixture.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Fixture
2222
{
2323
public function run(?int $flags = null)
2424
{
25-
$flags = $flags ?? JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRESERVE_ZERO_FRACTION;
25+
$flags = $flags ?? JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRESERVE_ZERO_FRACTION | 0;
2626

2727
json_encode([], $flags);
2828
}

0 commit comments

Comments
 (0)