Skip to content

Commit 83091c0

Browse files
committed
cs
1 parent de9d8f9 commit 83091c0

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Type/Php/CountFunctionReturnTypeExtension.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use PHPStan\Type\Type;
1414
use function count;
1515
use function in_array;
16-
use const COUNT_RECURSIVE;
16+
use const COUNT_NORMAL;
1717

1818
#[AutowiredService]
1919
final class CountFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
@@ -30,22 +30,23 @@ public function getTypeFromFunctionCall(
3030
Scope $scope,
3131
): ?Type
3232
{
33-
if (count($functionCall->getArgs()) < 1) {
33+
$args = $functionCall->getArgs();
34+
if (count($args) < 1) {
3435
return null;
3536
}
3637

37-
$arrayType = $scope->getType($functionCall->getArgs()[0]->value);
38+
$arrayType = $scope->getType($args[0]->value);
3839
if (!$this->isNormalCount($functionCall, $arrayType, $scope)->yes()) {
3940
if ($arrayType->isIterableAtLeastOnce()->yes()) {
4041
return IntegerRangeType::fromInterval(1, null);
4142
}
4243
return null;
4344
}
4445

45-
return $scope->getType($functionCall->getArgs()[0]->value)->getArraySize();
46+
return $scope->getType($args[0]->value)->getArraySize();
4647
}
4748

48-
private function isNormalCount(FuncCall $countFuncCall, Type $countedType, Scope $scope,): TrinaryLogic
49+
private function isNormalCount(FuncCall $countFuncCall, Type $countedType, Scope $scope): TrinaryLogic
4950
{
5051
if (count($countFuncCall->getArgs()) === 1) {
5152
$isNormalCount = TrinaryLogic::createYes();

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ public static function dataBinaryOperations(): array
24642464
'count($arrayOfIntegers)',
24652465
],
24662466
[
2467-
'int<0, max>',
2467+
'3',
24682468
'count($arrayOfIntegers, \COUNT_RECURSIVE)',
24692469
],
24702470
[

0 commit comments

Comments
 (0)