Skip to content

Commit

Permalink
improve mode parameter of count function
Browse files Browse the repository at this point in the history
  • Loading branch information
kuma3 committed Jun 26, 2024
1 parent 466e677 commit ae2dc75
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@
'Couchbase\WildcardSearchQuery::jsonSerialize' => ['array'],
'Couchbase\zlibCompress' => ['string', 'data'=>'string'],
'Couchbase\zlibDecompress' => ['string', 'data'=>'string'],
'count' => ['0|positive-int', 'var'=>'Countable|array', 'mode='=>'int'],
'count' => ['0|positive-int', 'var'=>'Countable|array', 'mode='=>'0|1'],
'count_chars' => ['mixed', 'input'=>'string', 'mode='=>'0|1|2|3|4'],
'Countable::count' => ['0|positive-int'],
'crack_check' => ['bool', 'dictionary'=>'', 'password'=>'string'],
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1716,4 +1716,18 @@ public function testCountArrayShift(): void
$this->analyse([__DIR__ . '/data/count-array-shift.php'], $errors);
}

public function testCount(): void
{
$this->analyse([__DIR__ . '/data/count.php'], [
[
'Parameter #2 $mode of function count expects 0|1, -1 given.',
9,
],
[
'Parameter #2 $mode of function count expects 0|1, int given.',
10,
],
]);
}

}
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Functions/data/count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace Count;

class Foo
{
public function doFoo(int $mode): void
{
count([1, 2, 3], -1);
count([1, 2, 3], $mode);
}
}

0 comments on commit ae2dc75

Please sign in to comment.