Skip to content

Commit

Permalink
Merge pull request #6083 from orklah/falsable-argument
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Jul 12, 2021
2 parents bbea459 + 52033f4 commit 6729f4d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
Expand Up @@ -1115,22 +1115,40 @@ public static function verifyType(
}
}

if ($input_type->isFalsable()
&& !$param_type->hasBool()
&& !$param_type->hasScalar()
&& !$input_type->ignore_falsable_issues
&& $cased_method_id !== 'echo'
if (!$param_type->isFalsable() &&
!$param_type->hasBool() &&
!$param_type->hasScalar() &&
$cased_method_id !== 'echo' &&
$cased_method_id !== 'print'
) {
if (IssueBuffer::accepts(
new PossiblyFalseArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' .
'false value provided',
$arg_location,
$cased_method_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
if ($input_type->isFalse()) {
if (IssueBuffer::accepts(
new InvalidArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, ' .
$param_type->getId() . ' value provided',
$arg_location,
$cased_method_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}

return null;
}

if ($input_type->isFalsable() && !$input_type->ignore_falsable_issues) {
if (IssueBuffer::accepts(
new PossiblyFalseArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' .
$param_type->getId() . ' value provided',
$arg_location,
$cased_method_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/FunctionCallTest.php
Expand Up @@ -2106,6 +2106,15 @@ function foo(string $s) {
$a = max($b, $c);',
'error_message' => 'MixedAssignment'
],
'literalFalseArgument' => [
'<?php
function takesAString(string $s): void{
echo $s;
}
takesAString(false);',
'error_message' => 'InvalidArgument'
],
];
}
}

0 comments on commit 6729f4d

Please sign in to comment.