Skip to content
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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
9 changes: 9 additions & 0 deletions src/Rules/UseSafeFunctionsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
$unsafeFunctions = FunctionListLoader::getFunctionList();

if (isset($unsafeFunctions[$functionName])) {
if ($functionName === "json_decode" || $functionName === "json_encode") {
foreach ($node->args as $arg) {
if ($arg->name instanceof Node\Identifier && $arg->name->toLowerString() === "flags") {

Check failure on line 38 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Access to an undefined property PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder::$name.

Check failure on line 38 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 8.0

Access to an undefined property PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder::$name.

Check failure on line 38 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Access to an undefined property PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder::$name.

Check failure on line 38 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 (lowest)

Access to an undefined property PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder::$name.
if ($this->argValueIncludeJSONTHROWONERROR($arg)) {

Check failure on line 39 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Parameter #1 $arg of method TheCodingMachine\Safe\PHPStan\Rules\UseSafeFunctionsRule::argValueIncludeJSONTHROWONERROR() expects PhpParser\Node\Arg|null, PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder given.

Check failure on line 39 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 8.0

Parameter #1 $arg of method TheCodingMachine\Safe\PHPStan\Rules\UseSafeFunctionsRule::argValueIncludeJSONTHROWONERROR() expects PhpParser\Node\Arg|null, PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder given.

Check failure on line 39 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Parameter #1 $arg of method TheCodingMachine\Safe\PHPStan\Rules\UseSafeFunctionsRule::argValueIncludeJSONTHROWONERROR() expects PhpParser\Node\Arg|null, PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder given.

Check failure on line 39 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 (lowest)

Parameter #1 $arg of method TheCodingMachine\Safe\PHPStan\Rules\UseSafeFunctionsRule::argValueIncludeJSONTHROWONERROR() expects PhpParser\Node\Arg|null, PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder given.
return [];
}
}
}
}
if (
$functionName === "json_decode"
&& $this->argValueIncludeJSONTHROWONERROR($node->getArgs()[3] ?? null)
Expand Down Expand Up @@ -63,7 +72,7 @@
if ($expr instanceof Expr\BinaryOp\BitwiseOr) {
return array_merge($parseValue($expr->left, $options), $parseValue($expr->right, $options));
} elseif ($expr instanceof Expr\ConstFetch) {
return array_merge($options, $expr->name->getParts());

Check failure on line 75 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 (lowest)

Call to an undefined method PhpParser\Node\Name::getParts().

Check failure on line 75 in src/Rules/UseSafeFunctionsRule.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 (lowest)

Parameter #2 ...$args of function array_merge expects array, mixed given.
} elseif ($expr instanceof Scalar\Int_) {
return array_merge($options, [$expr->value]);
} else {
Expand Down
Loading