2323use Rector \Enum \JsonConstant ;
2424use Rector \NodeAnalyzer \DefineFuncCallAnalyzer ;
2525use Rector \NodeTypeResolver \Node \AttributeKey ;
26+ use Rector \PhpParser \NodeTraverser \SimpleNodeTraverser ;
2627use Rector \Rector \AbstractRector ;
2728use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
2829use 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
6364CODE_SAMPLE
6465 ,
6566 <<<'CODE_SAMPLE'
66- $json json_encode($content, 0 );
67+ $json = json_encode($content);
6768if (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);
7273if (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