diff --git a/src/Rules/UseSafeFunctionsRule.php b/src/Rules/UseSafeFunctionsRule.php index a137779..aaba401 100644 --- a/src/Rules/UseSafeFunctionsRule.php +++ b/src/Rules/UseSafeFunctionsRule.php @@ -33,6 +33,19 @@ public function processNode(Node $node, Scope $scope): array $unsafeFunctions = FunctionListLoader::getFunctionList(); if (isset($unsafeFunctions[$functionName])) { + if ($functionName === "json_decode" || $functionName === "json_encode") { + foreach ($node->args as $arg) { + if ($arg instanceof Node\Arg && + $arg->name instanceof Node\Identifier && + $arg->name->toLowerString() === "flags" + ) { + if ($this->argValueIncludeJSONTHROWONERROR($arg)) { + return []; + } + } + } + } + if ($functionName === "json_decode" && $this->argValueIncludeJSONTHROWONERROR($node->getArgs()[3] ?? null) ) { diff --git a/tests/Rules/UseSafeFunctionsRuleTest.php b/tests/Rules/UseSafeFunctionsRuleTest.php index 55ba182..014bd6d 100644 --- a/tests/Rules/UseSafeFunctionsRuleTest.php +++ b/tests/Rules/UseSafeFunctionsRuleTest.php @@ -37,11 +37,11 @@ public function testExprCall(): void public function testJSONDecodeNoCatchSafe(): void { - $this->analyse([__DIR__ . '/data/safe_json_decode_for_7.3.0.php'], []); + $this->analyse([__DIR__ . '/data/safe_json_decode.php'], []); } public function testJSONEncodeNoCatchSafe(): void { - $this->analyse([__DIR__ . '/data/safe_json_encode_for_7.3.0.php'], []); + $this->analyse([__DIR__ . '/data/safe_json_encode.php'], []); } } diff --git a/tests/Rules/data/safe_json_decode_for_7.3.0.php b/tests/Rules/data/safe_json_decode.php similarity index 70% rename from tests/Rules/data/safe_json_decode_for_7.3.0.php rename to tests/Rules/data/safe_json_decode.php index c69e7ca..22b450a 100644 --- a/tests/Rules/data/safe_json_decode_for_7.3.0.php +++ b/tests/Rules/data/safe_json_decode.php @@ -1,9 +1,14 @@