From a07dc81948e89793882243249ee3cb1920972157 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 30 Jan 2022 11:36:43 +0100 Subject: [PATCH] Regression test --- .../PHPStan/Analyser/data/for-loop-i-type.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/PHPStan/Analyser/data/for-loop-i-type.php b/tests/PHPStan/Analyser/data/for-loop-i-type.php index 36b25f0dca..a0e2c2c53e 100644 --- a/tests/PHPStan/Analyser/data/for-loop-i-type.php +++ b/tests/PHPStan/Analyser/data/for-loop-i-type.php @@ -63,3 +63,41 @@ public function doLOrem() { } } + +class Capacity +{ + + function __construct(public mixed $current, public int $count) {} + +} +interface Foo2 { + function equals(self $other): bool; +} + +class HelloWorld +{ + /** + * @param Foo2[] $startTimes + * @return mixed[] + */ + public static function groupCapacities(array $startTimes): array + { + if ($startTimes === []) { + return []; + } + sort($startTimes); + + $capacities = []; + $current = $startTimes[0]; + $count = 0; + foreach ($startTimes as $startTime) { + if (!$startTime->equals($current)) { + $count = 0; + } + $count++; + } + assertType('int<1, max>', $count); + + return $capacities; + } +}