From f353dfa308db21027d5c0d347c157e306e59fbcd Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 11 Aug 2022 17:51:56 +0200 Subject: [PATCH 1/2] Consider named argument `flags:` for json_ function as Safe --- src/Rules/UseSafeFunctionsRule.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Rules/UseSafeFunctionsRule.php b/src/Rules/UseSafeFunctionsRule.php index cdbf205..0a33bea 100644 --- a/src/Rules/UseSafeFunctionsRule.php +++ b/src/Rules/UseSafeFunctionsRule.php @@ -55,6 +55,16 @@ public function processNode(Node $node, Scope $scope): array } } } + if ($functionName === "json_decode" || $functionName === "json_encode") { + foreach ($node->args as $arg) { + // Named argument might be not place on exact "documented" position + if ($arg->name instanceof Node\Identifier && $arg->name->toLowerString() === "flags") { + if ($this->argValueIncludeJSONTHROWONERROR($arg)) { + return []; + } + } + } + } } return ["Function $functionName is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\\$functionName;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library."]; From 485a114416026c7abdd4521a8bc7643d76216105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Michael?= Date: Sat, 23 Nov 2024 20:39:35 +0100 Subject: [PATCH 2/2] Update UseSafeFunctionsRule.php --- src/Rules/UseSafeFunctionsRule.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Rules/UseSafeFunctionsRule.php b/src/Rules/UseSafeFunctionsRule.php index fe91bac..4f3f76c 100644 --- a/src/Rules/UseSafeFunctionsRule.php +++ b/src/Rules/UseSafeFunctionsRule.php @@ -35,7 +35,6 @@ public function processNode(Node $node, Scope $scope): array if (isset($unsafeFunctions[$functionName])) { if ($functionName === "json_decode" || $functionName === "json_encode") { foreach ($node->args as $arg) { - // Named argument might be not place on exact "documented" position if ($arg->name instanceof Node\Identifier && $arg->name->toLowerString() === "flags") { if ($this->argValueIncludeJSONTHROWONERROR($arg)) { return [];