|
| 1 | +<?php // lint >= 8.0 |
| 2 | + |
| 3 | +namespace TemplateDefaultReferringOtherNested; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +class Entity |
| 8 | +{ |
| 9 | + |
| 10 | +} |
| 11 | + |
| 12 | +class User extends Entity |
| 13 | +{ |
| 14 | + |
| 15 | +} |
| 16 | + |
| 17 | +class Post extends Entity |
| 18 | +{ |
| 19 | + |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * @template TRelated of Entity |
| 24 | + * @template TDeclaring of Entity |
| 25 | + * @template TBare = TRelated |
| 26 | + * @template TResult = TRelated|null |
| 27 | + * @template TList of array = list<TRelated> |
| 28 | + * @template TShape of array = array{related: TRelated, declaring: TDeclaring} |
| 29 | + */ |
| 30 | +interface Relation |
| 31 | +{ |
| 32 | + |
| 33 | + /** @return TBare */ |
| 34 | + public function bare(): mixed; |
| 35 | + |
| 36 | + /** @return TResult */ |
| 37 | + public function getResults(): mixed; |
| 38 | + |
| 39 | + /** @return TList */ |
| 40 | + public function all(): array; |
| 41 | + |
| 42 | + /** @return TShape */ |
| 43 | + public function shape(): array; |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | +/** |
| 48 | + * @param Relation<User, Post> $defaulted |
| 49 | + * @param Relation<User, Post, User, User> $explicit |
| 50 | + */ |
| 51 | +function test(Relation $defaulted, Relation $explicit): void |
| 52 | +{ |
| 53 | + assertType('TemplateDefaultReferringOtherNested\User', $defaulted->bare()); |
| 54 | + assertType('TemplateDefaultReferringOtherNested\User|null', $defaulted->getResults()); |
| 55 | + assertType('list<TemplateDefaultReferringOtherNested\User>', $defaulted->all()); |
| 56 | + assertType('array{related: TemplateDefaultReferringOtherNested\User, declaring: TemplateDefaultReferringOtherNested\Post}', $defaulted->shape()); |
| 57 | + |
| 58 | + assertType('TemplateDefaultReferringOtherNested\User', $explicit->bare()); |
| 59 | + assertType('TemplateDefaultReferringOtherNested\User', $explicit->getResults()); |
| 60 | +} |
0 commit comments