forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bug-7500.php
48 lines (41 loc) · 1.13 KB
/
bug-7500.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php declare(strict_types = 1);
namespace Bug7500;
interface PositionEntityInterface {
public function getPosition(): int;
}
interface TgEntityInterface {}
abstract class HelloWorld
{
/**
* @phpstan-template T of PositionEntityInterface&TgEntityInterface
*
* @param iterable<T> $tgs
*
* @return array<T>
*
* @throws \Exception
*/
public function computeForFrontByPosition($tgs)
{
/** @phpstan-var array<T> $res */
$res = [];
foreach ($tgs as $tgItem) {
$position = $tgItem->getPosition();
if (!isset($res[$position])) {
$res[$position] = $tgItem;
} else {
$tgItemToKeep = $this->compare($tgItem, $res[$position]);
$res[$position] = $tgItemToKeep;
}
}
ksort($res);
return $res;
}
/**
* @phpstan-template T of TgEntityInterface
* @phpstan-param T $nextTg
* @phpstan-param T $currentTg
* @phpstan-return T
*/
abstract protected function compare(TgEntityInterface $nextTg, TgEntityInterface $currentTg): TgEntityInterface;
}