-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dfe8b8
commit 8d03f8f
Showing
2 changed files
with
69 additions
and
3 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
65 changes: 65 additions & 0 deletions
65
tests/Doctrine/StaticAnalysis/Tools/Pagination/paginator-covariant.php
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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\StaticAnalysis\Tools\Pagination; | ||
|
||
use Doctrine\ORM\Tools\Pagination\Paginator; | ||
|
||
/** | ||
* @template-covariant T of object | ||
*/ | ||
abstract class PaginatorFactory | ||
{ | ||
/** @var class-string<T> */ | ||
private $class; | ||
|
||
/** | ||
* @param class-string<T> $class | ||
*/ | ||
final public function __construct(string $class) | ||
{ | ||
$this->class = $class; | ||
} | ||
|
||
/** | ||
* @return class-string<T> | ||
*/ | ||
public function getClass(): string | ||
{ | ||
return $this->class; | ||
} | ||
|
||
/** | ||
* @psalm-return Paginator<T> | ||
*/ | ||
abstract public function createPaginator(): Paginator; | ||
} | ||
|
||
interface Animal | ||
{ | ||
} | ||
|
||
class Cat implements Animal | ||
{ | ||
} | ||
|
||
/** | ||
* @param Paginator<Animal> $paginator | ||
*/ | ||
function getFirstAnimal(Paginator $paginator): ?Animal | ||
{ | ||
foreach ($paginator as $result) { | ||
return $result; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param PaginatorFactory<Cat> $catPaginatorFactory | ||
*/ | ||
function test(PaginatorFactory $catPaginatorFactory): ?Animal | ||
{ | ||
return getFirstAnimal($catPaginatorFactory->createPaginator()); | ||
} |
8d03f8f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, due to this change I got a phpstan issue when calling
$paginator->getIterator()->getArrayCopy()
:8d03f8f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think a valid way would be to use
iterator_to_array($paginator->getIterator())
as a replacement in that case?