Skip to content

Commit 88a7b43

Browse files
committed
misc
1 parent 7e36ecf commit 88a7b43

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,6 @@ parameters:
113113
- rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php
114114
- rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php
115115
- rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php
116+
117+
# local attribute key
118+
- '#Parameter \#2 \$attributeKey of static method Rector\\PhpParser\\NodeTraverser\\SimpleNodeTraverser\:\:decorateWithAttributeValue\(\) expects#'

rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Rector\Enum\JsonConstant;
2424
use Rector\NodeAnalyzer\DefineFuncCallAnalyzer;
2525
use Rector\NodeTypeResolver\Node\AttributeKey;
26+
use Rector\PhpParser\NodeTraverser\SimpleNodeTraverser;
2627
use Rector\Rector\AbstractRector;
2728
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2829
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -42,7 +43,7 @@ final class DowngradePhp73JsonConstRector extends AbstractRector
4243
/**
4344
* @var array<string>
4445
*/
45-
private const REFACTOR_FUNCS = ['json_decode', 'json_encode'];
46+
private const JSON_FUNCTIONS = ['json_decode', 'json_encode'];
4647

4748
public function __construct(
4849
private readonly JsonConstCleaner $jsonConstCleaner,
@@ -63,12 +64,12 @@ public function getRuleDefinition(): RuleDefinition
6364
CODE_SAMPLE
6465
,
6566
<<<'CODE_SAMPLE'
66-
$json json_encode($content, 0);
67+
$json = json_encode($content);
6768
if (json_last_error() !== JSON_ERROR_NONE) {
6869
throw new \Exception(json_last_error_msg());
6970
}
7071
71-
$content = json_decode($json, null, 512, 0);
72+
$content = json_decode($json, null, 512);
7273
if (json_last_error() !== JSON_ERROR_NONE) {
7374
throw new \Exception(json_last_error_msg());
7475
}
@@ -115,10 +116,7 @@ private function markConstantKnownInInnerStmts(If_ $if): void
115116
return;
116117
}
117118

118-
$this->traverseNodesWithCallable($if, static function (Node $node): null {
119-
$node->setAttribute(self::PHP73_JSON_CONSTANT_IS_KNOWN, true);
120-
return null;
121-
});
119+
SimpleNodeTraverser::decorateWithAttributeValue($if, self::PHP73_JSON_CONSTANT_IS_KNOWN, true);
122120
}
123121

124122
private function resolveFuncCall(Expression $Expression): ?FuncCall
@@ -164,7 +162,7 @@ private function refactorExpression(Expression $expression): ?array
164162
}
165163

166164
// Nothing to do if not a refactored function
167-
if (! in_array($this->getName($funcCall), self::REFACTOR_FUNCS, true)) {
165+
if (! in_array($this->getName($funcCall), self::JSON_FUNCTIONS, true)) {
168166
return null;
169167
}
170168

0 commit comments

Comments
 (0)