-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TemplateTypeArgumentStrategy::accepts()
- Loading branch information
1 parent
5b2d7b6
commit 85ab8cf
Showing
3 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Bug7460; | ||
|
||
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 { | ||
/** @phpstan-var T $tgItemToKeep */ | ||
$tgItemToKeep = $this->compare($tgItem, $res[$position]); | ||
$res[$position] = $tgItemToKeep; | ||
} | ||
} | ||
ksort($res); | ||
|
||
return $res; | ||
} | ||
|
||
/** | ||
* @phpstan-template T of PositionEntityInterface&TgEntityInterface | ||
* | ||
* @param iterable<T> $tgs | ||
* | ||
* @return array<T> | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function computeForFrontByPosition2($tgs) | ||
{ | ||
/** @phpstan-var array<T> $res */ | ||
$res = []; | ||
|
||
foreach ($tgs as $tgItem) { | ||
$position = $tgItem->getPosition(); | ||
|
||
if (!isset($res[$position])) { | ||
$res[$position] = $tgItem; | ||
} else { | ||
/** @phpstan-var T $tgItemToKeep */ | ||
$tgItemToKeep = $this->compare($tgItem, $res[$position]); | ||
$res[$position] = $tgItemToKeep; | ||
} | ||
} | ||
ksort($res); | ||
|
||
return $res; | ||
} | ||
|
||
/** | ||
* @phpstan-template S of TgEntityInterface | ||
* @phpstan-param S $nextTg | ||
* @phpstan-param S $currentTg | ||
* @phpstan-return S | ||
*/ | ||
abstract protected function compare(TgEntityInterface $nextTg, TgEntityInterface $currentTg): TgEntityInterface; | ||
} |