Skip to content

Commit f353dfa

Browse files
authored
Consider named argument flags: for json_ function as Safe
1 parent 8a7b88e commit f353dfa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Rules/UseSafeFunctionsRule.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public function processNode(Node $node, Scope $scope): array
5555
}
5656
}
5757
}
58+
if ($functionName === "json_decode" || $functionName === "json_encode") {
59+
foreach ($node->args as $arg) {
60+
// Named argument might be not place on exact "documented" position
61+
if ($arg->name instanceof Node\Identifier && $arg->name->toLowerString() === "flags") {
62+
if ($this->argValueIncludeJSONTHROWONERROR($arg)) {
63+
return [];
64+
}
65+
}
66+
}
67+
}
5868
}
5969

6070
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."];

0 commit comments

Comments
 (0)