Skip to content

Consider named argument flags:JSON_THROW_ON_ERROR for json_ functions as "Safe" #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Rules/UseSafeFunctionsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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."];
Expand Down