Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Bug8008; | ||
|
||
use function \PHPStan\Testing\assertType; | ||
|
||
/** | ||
* @template TValue | ||
*/ | ||
class Collection | ||
{ | ||
/** | ||
* @param array<TValue> $items | ||
*/ | ||
public function __construct( | ||
public array $items, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array<TValue> | ||
*/ | ||
public function all() { | ||
return $this->items; | ||
} | ||
} | ||
|
||
/** | ||
* @template TValue of object | ||
* | ||
* @mixin Collection<TValue> | ||
*/ | ||
class Paginator | ||
{ | ||
/** | ||
* @var Collection<TValue> | ||
*/ | ||
public Collection $collection; | ||
|
||
/** | ||
* @param array<TValue> $items | ||
*/ | ||
public function __construct(public array $items) | ||
{ | ||
$this->collection = new Collection($items); | ||
} | ||
} | ||
|
||
class MyObject {} | ||
|
||
|
||
function (): void { | ||
$paginator = new Paginator([new MyObject()]); | ||
|
||
assertType('Bug8008\Paginator<Bug8008\MyObject>', $paginator); | ||
assertType('array<Bug8008\MyObject>', $paginator->items); | ||
assertType('Bug8008\Collection<Bug8008\MyObject>', $paginator->collection); | ||
assertType('array<Bug8008\MyObject>', $paginator->collection->items); | ||
|
||
assertType('array<Bug8008\MyObject>', $paginator->all()); | ||
}; |