Skip to content

Commit 7680382

Browse files
committed
Updated with constant types support
1 parent f6d55c6 commit 7680382

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

Diff for: src/Rules/StrictCalls/StrictFunctionCallsRule.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PHPStan\Rules\StrictCalls;
44

5+
use PHPStan\Type\Constant\ConstantBooleanType;
6+
57
class StrictFunctionCallsRule implements \PHPStan\Rules\Rule
68
{
79

@@ -56,7 +58,8 @@ public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scop
5658
}
5759

5860
$argumentType = $scope->getType($node->args[$argumentPosition]->value);
59-
if (!$argumentType instanceof \PHPStan\Type\TrueBooleanType) {
61+
$trueType = new ConstantBooleanType(true);
62+
if (!$trueType->isSuperTypeOf($argumentType)->yes()) {
6063
return [sprintf('Call to function %s() requires parameter #%d to be true.', $functionName, $argumentPosition + 1)];
6164
}
6265

Diff for: tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function testRule(): void
6363
'Call to function array_keys() requires parameter #3 to be set.',
6464
23,
6565
],
66+
[
67+
'Call to function array_keys() requires parameter #3 to be true.',
68+
31,
69+
],
6670
]);
6771
}
6872

Diff for: tests/Rules/StrictCalls/data/strict-calls.php

+4
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@
2525

2626
$dynamicCall = 'foo';
2727
$dynamicCall();
28+
29+
/** @var bool $bool */
30+
$bool = doFoo();
31+
array_keys([1, 2, 3], 1, $bool);

Diff for: tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ public function testRule(): void
1616
{
1717
$this->analyse([__DIR__ . '/data/matching-type.php'], [
1818
[
19-
'Switch condition type (int) does not match case condition \'test\' (string).',
19+
'Switch condition type (int(1)) does not match case condition \'test\' (string).',
2020
8,
2121
],
2222
[
23-
'Switch condition type (int) does not match case condition 1 > 2 (bool).',
23+
'Switch condition type (int(1)) does not match case condition 1 > 2 (bool).',
2424
8,
2525
],
2626
[
27-
'Switch condition type (string) does not match case condition 1 (int).',
27+
'Switch condition type (string) does not match case condition 1 (int(1)).',
28+
19,
29+
],
30+
[
31+
'Switch condition type (string) does not match case condition \'test\' (string).',
2832
19,
2933
],
3034
[

0 commit comments

Comments
 (0)