diff --git a/src/Analyser/TypeSpecifier.php b/src/Analyser/TypeSpecifier.php index 485d8277cf..52b3d76d45 100644 --- a/src/Analyser/TypeSpecifier.php +++ b/src/Analyser/TypeSpecifier.php @@ -1068,6 +1068,7 @@ private function specifyTypesForCountFuncCall( !$isNormalCount->yes() || (!$isConstantArray->yes() && !$isList->yes()) || !$oneOrMore->isSuperTypeOf($sizeType)->yes() + || $sizeType->isSuperTypeOf($type->getArraySize())->yes() ) { return null; } diff --git a/tests/PHPStan/Analyser/nsrt/count-const-array-2.php b/tests/PHPStan/Analyser/nsrt/count-const-array-2.php new file mode 100644 index 0000000000..f83d7d8b5f --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/count-const-array-2.php @@ -0,0 +1,35 @@ + $limit + * @return list<\stdClass> + */ + public function searchRecommendedMinPrices(int $limit): array + { + $bestMinPrice = new \stdClass(); + $limit--; + if ($limit === 0) { + return [$bestMinPrice]; + } + + $otherMinPrices = [new \stdClass()]; + while (count($otherMinPrices) < $limit) { + $otherMinPrice = new \stdClass(); + if (rand(0, 1)) { + $otherMinPrice = null; + } + if ($otherMinPrice === null) { + break; + } + array_unshift($otherMinPrices, $otherMinPrice); + } + assertType('non-empty-list', $otherMinPrices); + return [$bestMinPrice, ...$otherMinPrices]; + } +} diff --git a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php index 7c80c91cd6..2ba73fdc96 100644 --- a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php @@ -139,11 +139,6 @@ public function testBug1216(): void ]); } - public function testBug1311(): void - { - $this->analyse([__DIR__ . '/data/bug-1311.php'], []); - } - public function testTypesAssignedToPropertiesExpressionNames(): void { $this->analyse([__DIR__ . '/data/properties-from-array-into-object.php'], [ diff --git a/tests/PHPStan/Rules/Properties/data/bug-1311.php b/tests/PHPStan/Rules/Properties/data/bug-1311.php deleted file mode 100755 index 995f2d8216..0000000000 --- a/tests/PHPStan/Rules/Properties/data/bug-1311.php +++ /dev/null @@ -1,24 +0,0 @@ - - */ - private $list = []; - - public function convertList(): void - { - $temp = [1, 2, 3]; - - for ($i = 0; $i < count($temp); $i++) { - $temp[$i] = (string) $temp[$i]; - } - - $this->list = $temp; - } -} - -(new HelloWorld())->convertList();