diff --git a/composer.json b/composer.json index 191afcda..ec6397da 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,10 @@ "dg/bypass-finals": "^1.5.1", "jackalope/jackalope-doctrine-dbal": "^1.9 || ^2.0", "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "1.12.11", - "phpstan/phpstan-phpunit": "1.4.0", + "phpstan/phpstan": "2.0.3", + "phpstan/phpstan-phpunit": "2.0.1", "phpunit/phpunit": "10.5.38", - "rector/rector": "1.2.10", + "rector/rector": "2.0.0-rc1", "ruflin/elastica": "^7.3 || ^8.0", "solarium/solarium": "^6.2", "symfony/cache": "^5.4 || ^6.3 || ^7.0", diff --git a/lib/Adapter/Doctrine/Collections/CollectionAdapter.php b/lib/Adapter/Doctrine/Collections/CollectionAdapter.php index 4bb615e4..614ab947 100644 --- a/lib/Adapter/Doctrine/Collections/CollectionAdapter.php +++ b/lib/Adapter/Doctrine/Collections/CollectionAdapter.php @@ -23,7 +23,7 @@ public function __construct( ) {} /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -31,8 +31,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Adapter/Doctrine/Collections/SelectableAdapter.php b/lib/Adapter/Doctrine/Collections/SelectableAdapter.php index 6315662b..20669783 100644 --- a/lib/Adapter/Doctrine/Collections/SelectableAdapter.php +++ b/lib/Adapter/Doctrine/Collections/SelectableAdapter.php @@ -25,7 +25,7 @@ public function __construct( ) {} /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -33,8 +33,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ @@ -44,8 +44,8 @@ public function getSlice(int $offset, int $length): iterable } /** - * @phpstan-param int<0, max> $firstResult - * @phpstan-param int<0, max>|null $maxResult + * @param int<0, max> $firstResult + * @param int<0, max>|null $maxResult */ private function createCriteria(int $firstResult, ?int $maxResult): Criteria { diff --git a/lib/Adapter/Doctrine/Collections/Tests/CollectionAdapterTest.php b/lib/Adapter/Doctrine/Collections/Tests/CollectionAdapterTest.php index e4c06faa..cad5ccab 100644 --- a/lib/Adapter/Doctrine/Collections/Tests/CollectionAdapterTest.php +++ b/lib/Adapter/Doctrine/Collections/Tests/CollectionAdapterTest.php @@ -9,12 +9,12 @@ final class CollectionAdapterTest extends TestCase { /** - * @var ArrayCollection + * @var ArrayCollection> */ private ArrayCollection $collection; /** - * @var CollectionAdapter + * @var CollectionAdapter> */ private CollectionAdapter $adapter; @@ -27,11 +27,15 @@ protected function setUp(): void public function testGetNbResultsShouldResultTheCollectionCount(): void { - self::assertSame($this->collection->count(), $this->adapter->getNbResults()); + $this->assertSame($this->collection->count(), $this->adapter->getNbResults()); } public function testGetResultsShouldReturnTheCollectionSliceReturnValue(): void { - self::assertSame(array_values(range(6, 17)), array_values($this->adapter->getSlice(5, 12))); + $slice = $this->adapter->getSlice(5, 12); + + \assert(\is_array($slice)); + + $this->assertSame(array_values(range(6, 17)), array_values($slice)); } } diff --git a/lib/Adapter/Doctrine/Collections/Tests/SelectableAdapterTest.php b/lib/Adapter/Doctrine/Collections/Tests/SelectableAdapterTest.php index 2926b15f..85a723ef 100644 --- a/lib/Adapter/Doctrine/Collections/Tests/SelectableAdapterTest.php +++ b/lib/Adapter/Doctrine/Collections/Tests/SelectableAdapterTest.php @@ -51,12 +51,12 @@ public function testGetNbResults(): void $collection->method('count') ->willReturn(10); - $this->selectable->expects(self::once()) + $this->selectable->expects($this->once()) ->method('matching') ->with($this->criteria) ->willReturn($collection); - self::assertSame(10, $this->adapter->getNbResults()); + $this->assertSame(10, $this->adapter->getNbResults()); } public function testGetSlice(): void @@ -66,11 +66,11 @@ public function testGetSlice(): void $slice = []; - $this->selectable->expects(self::once()) + $this->selectable->expects($this->once()) ->method('matching') ->with($this->criteria) ->willReturn($slice); - self::assertSame($slice, $this->adapter->getSlice(10, 20)); + $this->assertSame($slice, $this->adapter->getSlice(10, 20)); } } diff --git a/lib/Adapter/Doctrine/DBAL/QueryAdapter.php b/lib/Adapter/Doctrine/DBAL/QueryAdapter.php index d02c9dbc..05a50ed6 100644 --- a/lib/Adapter/Doctrine/DBAL/QueryAdapter.php +++ b/lib/Adapter/Doctrine/DBAL/QueryAdapter.php @@ -17,14 +17,12 @@ class QueryAdapter implements AdapterInterface private readonly QueryBuilder $queryBuilder; /** - * @var callable - * - * @phpstan-var callable(QueryBuilder): (QueryBuilder|void) + * @var callable(QueryBuilder): (QueryBuilder|void) */ private $countQueryBuilderModifier; /** - * @phpstan-param callable(QueryBuilder): (QueryBuilder|void) $countQueryBuilderModifier + * @param callable(QueryBuilder): (QueryBuilder|void) $countQueryBuilderModifier */ public function __construct(QueryBuilder $queryBuilder, callable $countQueryBuilderModifier) { @@ -33,7 +31,7 @@ public function __construct(QueryBuilder $queryBuilder, callable $countQueryBuil } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -43,8 +41,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Adapter/Doctrine/DBAL/SingleTableQueryAdapter.php b/lib/Adapter/Doctrine/DBAL/SingleTableQueryAdapter.php index 8933b9d2..1d3f0677 100644 --- a/lib/Adapter/Doctrine/DBAL/SingleTableQueryAdapter.php +++ b/lib/Adapter/Doctrine/DBAL/SingleTableQueryAdapter.php @@ -31,6 +31,7 @@ private function createCountQueryModifier(string $countField): \Closure return static function (QueryBuilder $queryBuilder) use ($select): QueryBuilder { $queryBuilder->select($select); + /** @phpstan-ignore-next-line function.alreadyNarrowedType */ if (method_exists($queryBuilder, 'resetOrderBy')) { $queryBuilder->resetOrderBy(); } else { diff --git a/lib/Adapter/Doctrine/DBAL/Tests/QueryAdapterTest.php b/lib/Adapter/Doctrine/DBAL/Tests/QueryAdapterTest.php index d23765b4..d5087ce0 100644 --- a/lib/Adapter/Doctrine/DBAL/Tests/QueryAdapterTest.php +++ b/lib/Adapter/Doctrine/DBAL/Tests/QueryAdapterTest.php @@ -29,14 +29,14 @@ static function (QueryBuilder $qb): void { } ); - self::assertSame(50, $adapter->getNbResults()); + $this->assertSame(50, $adapter->getNbResults()); } public function testAdapterReturnsNumberOfResults(): void { $adapter = $this->createAdapterToTestGetNbResults(); - self::assertSame(50, $adapter->getNbResults()); + $this->assertSame(50, $adapter->getNbResults()); } public function testResultCountStaysConsistentAfterSlicing(): void @@ -45,7 +45,7 @@ public function testResultCountStaysConsistentAfterSlicing(): void $adapter->getSlice(1, 10); - self::assertSame(50, $adapter->getNbResults()); + $this->assertSame(50, $adapter->getNbResults()); } public function testGetSlice(): void @@ -58,7 +58,7 @@ public function testGetSlice(): void $this->qb->setFirstResult($offset) ->setMaxResults($length); - self::assertSame($this->qb->executeQuery()->fetchAllAssociative(), $adapter->getSlice($offset, $length)); + $this->assertSame($this->qb->executeQuery()->fetchAllAssociative(), $adapter->getSlice($offset, $length)); } public function testTheAdapterUsesAClonedQuery(): void @@ -68,7 +68,7 @@ public function testTheAdapterUsesAClonedQuery(): void $this->qb->innerJoin('p', 'comments', 'c', 'c.post_id = p.id') ->groupBy('c.post_id'); - self::assertSame(50, $adapter->getNbResults()); + $this->assertSame(50, $adapter->getNbResults()); } /** diff --git a/lib/Adapter/Doctrine/DBAL/Tests/SingleTableQueryAdapterTest.php b/lib/Adapter/Doctrine/DBAL/Tests/SingleTableQueryAdapterTest.php index 805a9883..8353d78d 100644 --- a/lib/Adapter/Doctrine/DBAL/Tests/SingleTableQueryAdapterTest.php +++ b/lib/Adapter/Doctrine/DBAL/Tests/SingleTableQueryAdapterTest.php @@ -35,14 +35,14 @@ public function testACountFieldWithoutAnAliasIsRejected(): void public function testAdapterReturnsNumberOfResults(): void { - self::assertSame(50, $this->adapter->getNbResults()); + $this->assertSame(50, $this->adapter->getNbResults()); } public function testResultCountStaysConsistentAfterSlicing(): void { $this->adapter->getSlice(1, 10); - self::assertSame(50, $this->adapter->getNbResults()); + $this->assertSame(50, $this->adapter->getNbResults()); } public function testGetSlice(): void @@ -54,6 +54,6 @@ public function testGetSlice(): void $q->setFirstResult($offset) ->setMaxResults($length); - self::assertSame($q->executeQuery()->fetchAllAssociative(), $this->adapter->getSlice($offset, $length)); + $this->assertSame($q->executeQuery()->fetchAllAssociative(), $this->adapter->getSlice($offset, $length)); } } diff --git a/lib/Adapter/Doctrine/MongoDBODM/AggregationAdapter.php b/lib/Adapter/Doctrine/MongoDBODM/AggregationAdapter.php index f0da454c..4e35f016 100644 --- a/lib/Adapter/Doctrine/MongoDBODM/AggregationAdapter.php +++ b/lib/Adapter/Doctrine/MongoDBODM/AggregationAdapter.php @@ -19,7 +19,7 @@ public function __construct( ) {} /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -34,8 +34,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Adapter/Doctrine/MongoDBODM/QueryAdapter.php b/lib/Adapter/Doctrine/MongoDBODM/QueryAdapter.php index ce5b833c..accde02d 100644 --- a/lib/Adapter/Doctrine/MongoDBODM/QueryAdapter.php +++ b/lib/Adapter/Doctrine/MongoDBODM/QueryAdapter.php @@ -19,7 +19,7 @@ public function __construct( ) {} /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -33,8 +33,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Adapter/Doctrine/MongoDBODM/Tests/AggregationAdapterTest.php b/lib/Adapter/Doctrine/MongoDBODM/Tests/AggregationAdapterTest.php index e5276dd9..3ed508a4 100644 --- a/lib/Adapter/Doctrine/MongoDBODM/Tests/AggregationAdapterTest.php +++ b/lib/Adapter/Doctrine/MongoDBODM/Tests/AggregationAdapterTest.php @@ -47,29 +47,29 @@ public function testGetNbResultsShouldResetHydrationAndAddCountStage(): void /** @var MockObject&Count $countStage */ $countStage = $this->createMock(Count::class); - $countStage->expects(self::once()) + $countStage->expects($this->once()) ->method('getAggregation') ->willReturn($aggregation); - $resultIterator->expects(self::once()) + $resultIterator->expects($this->once()) ->method('toArray') ->willReturn([['numResults' => 110]]); - $aggregation->expects(self::once()) + $aggregation->expects($this->once()) ->method('getIterator') ->willReturn($resultIterator); - $this->aggregationBuilder->expects(self::once()) + $this->aggregationBuilder->expects($this->once()) ->method('hydrate') ->with(null) ->willReturnSelf(); - $this->aggregationBuilder->expects(self::once()) + $this->aggregationBuilder->expects($this->once()) ->method('count') ->with('numResults') ->willReturn($countStage); - self::assertSame(110, $this->adapter->getNbResults()); + $this->assertSame(110, $this->adapter->getNbResults()); } public function testGetSlice(): void @@ -89,24 +89,24 @@ public function testGetSlice(): void /** @var MockObject&Limit $limitStage */ $limitStage = $this->createMock(Limit::class); - $skipStage->expects(self::once()) + $skipStage->expects($this->once()) ->method('limit') ->with($length) ->willReturn($limitStage); - $limitStage->expects(self::once()) + $limitStage->expects($this->once()) ->method('getAggregation') ->willReturn($aggregation); - $aggregation->expects(self::once()) + $aggregation->expects($this->once()) ->method('getIterator') ->willReturn($slice); - $this->aggregationBuilder->expects(self::once()) + $this->aggregationBuilder->expects($this->once()) ->method('skip') ->with($offset) ->willReturn($skipStage); - self::assertSame($slice, $this->adapter->getSlice($offset, $length)); + $this->assertSame($slice, $this->adapter->getSlice($offset, $length)); } } diff --git a/lib/Adapter/Doctrine/MongoDBODM/Tests/QueryAdapterTest.php b/lib/Adapter/Doctrine/MongoDBODM/Tests/QueryAdapterTest.php index f860b3e1..4ef7d066 100644 --- a/lib/Adapter/Doctrine/MongoDBODM/Tests/QueryAdapterTest.php +++ b/lib/Adapter/Doctrine/MongoDBODM/Tests/QueryAdapterTest.php @@ -37,27 +37,27 @@ public function testGetNbResultsShouldCreateTheQueryAndCount(): void /** @var MockObject&Query $query */ $query = $this->createMock(Query::class); - $query->expects(self::once()) + $query->expects($this->once()) ->method('execute') ->willReturn(110); - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('limit') ->willReturnSelf(); - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('skip') ->willReturnSelf(); - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('count') ->willReturnSelf(); - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('getQuery') ->willReturn($query); - self::assertSame(110, $this->adapter->getNbResults()); + $this->assertSame(110, $this->adapter->getNbResults()); } public function testGetSlice(): void @@ -68,24 +68,24 @@ public function testGetSlice(): void /** @var MockObject&Query $query */ $query = $this->createMock(Query::class); - $query->expects(self::once()) + $query->expects($this->once()) ->method('execute') ->willReturn($slice); - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('limit') ->with($length) ->willReturnSelf(); - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('skip') ->with($offset) ->willReturnSelf(); - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('getQuery') ->willReturn($query); - self::assertSame($slice, $this->adapter->getSlice($offset, $length)); + $this->assertSame($slice, $this->adapter->getSlice($offset, $length)); } } diff --git a/lib/Adapter/Doctrine/ORM/QueryAdapter.php b/lib/Adapter/Doctrine/ORM/QueryAdapter.php index f7ca2e3d..696848df 100644 --- a/lib/Adapter/Doctrine/ORM/QueryAdapter.php +++ b/lib/Adapter/Doctrine/ORM/QueryAdapter.php @@ -35,7 +35,7 @@ public function __construct( } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -43,8 +43,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return \Traversable */ diff --git a/lib/Adapter/Doctrine/ORM/Tests/QueryAdapterTest.php b/lib/Adapter/Doctrine/ORM/Tests/QueryAdapterTest.php index f275da30..1ff5f5f3 100644 --- a/lib/Adapter/Doctrine/ORM/Tests/QueryAdapterTest.php +++ b/lib/Adapter/Doctrine/ORM/Tests/QueryAdapterTest.php @@ -60,16 +60,19 @@ public function testAdapterReturnsNumberOfResultsForSingleTableQuery(): void { $adapter = new QueryAdapter($this->entityManager->createQuery('SELECT u FROM '.User::class.' u')); - self::assertSame(2, $adapter->getNbResults()); + $this->assertSame(2, $adapter->getNbResults()); } public function testAdapterReturnsNumberOfResultsForAJoinedCollection(): void { $adapter = new QueryAdapter($this->entityManager->createQuery('SELECT u, g FROM '.User::class.' u INNER JOIN u.groups g')); - self::assertSame(2, $adapter->getNbResults()); + $this->assertSame(2, $adapter->getNbResults()); } + /** + * @return \Generator, 1: int<0, max>, 2: int<0, max>}> + */ public static function dataGetSlice(): \Generator { yield '0 offset, 1 item' => [0, 1, 1]; @@ -78,27 +81,29 @@ public static function dataGetSlice(): \Generator } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length + * @param int<0, max> $expectedCount */ #[DataProvider('dataGetSlice')] public function testCurrentPageSliceForSingleTableQuery(int $offset, int $length, int $expectedCount): void { $adapter = new QueryAdapter($this->entityManager->createQuery('SELECT u FROM '.User::class.' u')); - self::assertCount($expectedCount, $adapter->getSlice($offset, $length)); + $this->assertCount($expectedCount, $adapter->getSlice($offset, $length)); } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length + * @param int<0, max> $expectedCount */ #[DataProvider('dataGetSlice')] public function testCurrentPageSliceForAJoinedCollection(int $offset, int $length, int $expectedCount): void { $adapter = new QueryAdapter($this->entityManager->createQuery('SELECT u, g FROM '.User::class.' u INNER JOIN u.groups g')); - self::assertCount($expectedCount, $adapter->getSlice($offset, $length)); + $this->assertCount($expectedCount, $adapter->getSlice($offset, $length)); } public function testResultCountStaysConsistentAfterSlicing(): void @@ -108,19 +113,19 @@ public function testResultCountStaysConsistentAfterSlicing(): void $adapter->getSlice(0, 1); - self::assertSame($results, $adapter->getNbResults()); + $this->assertSame($results, $adapter->getNbResults()); } public function testResultSetIsSlicedWhenSelectingEntitiesAndSingleFields(): void { $adapter = new QueryAdapter($this->entityManager->createQuery('SELECT p, p.name FROM '.Person::class.' p')); - self::assertSame(2, $adapter->getNbResults()); + $this->assertSame(2, $adapter->getNbResults()); $items = $adapter->getSlice(0, 10); - self::assertCount(2, $items); - self::assertArrayHasKey('name', $items[0]); + $this->assertCount(2, $items); + $this->assertArrayHasKey('name', $items[0]); } public function testResultSetIsLoadedWithCaseInSelectStatement(): void @@ -149,12 +154,12 @@ public function testResultSetIsLoadedWithCaseInSelectStatement(): void $adapter = new QueryAdapter($query); - self::assertSame(1, $adapter->getNbResults()); + $this->assertSame(1, $adapter->getNbResults()); $items = $adapter->getSlice(0, 10); - self::assertSame('Foo', $items[0][0]->name); - self::assertSame(1, $items[0]['relevance']); + $this->assertSame('Foo', $items[0][0]->name); + $this->assertSame(1, $items[0]['relevance']); } public function testAQueryBuilderIsAccepted(): void @@ -165,7 +170,7 @@ public function testAQueryBuilderIsAccepted(): void $adapter = new QueryAdapter($queryBuilder); - self::assertSame(2, $adapter->getNbResults()); - self::assertCount(2, $adapter->getSlice(0, 10)); + $this->assertSame(2, $adapter->getNbResults()); + $this->assertCount(2, $adapter->getSlice(0, 10)); } } diff --git a/lib/Adapter/Doctrine/PHPCRODM/QueryAdapter.php b/lib/Adapter/Doctrine/PHPCRODM/QueryAdapter.php index 419667f4..b908563e 100644 --- a/lib/Adapter/Doctrine/PHPCRODM/QueryAdapter.php +++ b/lib/Adapter/Doctrine/PHPCRODM/QueryAdapter.php @@ -20,7 +20,7 @@ public function __construct( ) {} /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -31,8 +31,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Adapter/Doctrine/PHPCRODM/Tests/QueryAdapterTest.php b/lib/Adapter/Doctrine/PHPCRODM/Tests/QueryAdapterTest.php index 0e260264..2c5413fe 100644 --- a/lib/Adapter/Doctrine/PHPCRODM/Tests/QueryAdapterTest.php +++ b/lib/Adapter/Doctrine/PHPCRODM/Tests/QueryAdapterTest.php @@ -30,21 +30,21 @@ protected function setUp(): void public function testGetNbResultsShouldCreateTheQueryAndCount(): void { - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('getQuery') ->willReturn($this->query); /** @var MockObject&QueryResultInterface $queryResult */ $queryResult = $this->createMock(QueryResultInterface::class); - $queryResult->expects(self::once()) + $queryResult->expects($this->once()) ->method('getRows') ->willReturn(new \ArrayIterator([1, 2, 3, 4, 5, 6])); - $this->query->expects(self::once()) + $this->query->expects($this->once()) ->method('execute') ->willReturn($queryResult); - self::assertSame(6, $this->adapter->getNbResults()); + $this->assertSame(6, $this->adapter->getNbResults()); } public function testGetSlice(): void @@ -53,24 +53,24 @@ public function testGetSlice(): void $length = 15; $slice = new \ArrayIterator(); - $this->query->expects(self::once()) + $this->query->expects($this->once()) ->method('setMaxResults') ->with($length) ->willReturn($this->query); - $this->query->expects(self::once()) + $this->query->expects($this->once()) ->method('setFirstResult') ->with($offset) ->willReturn($this->query); - $this->queryBuilder->expects(self::once()) + $this->queryBuilder->expects($this->once()) ->method('getQuery') ->willReturn($this->query); - $this->query->expects(self::once()) + $this->query->expects($this->once()) ->method('execute') ->willReturn($slice); - self::assertSame($slice, $this->adapter->getSlice($offset, $length)); + $this->assertSame($slice, $this->adapter->getSlice($offset, $length)); } } diff --git a/lib/Adapter/Elastica/ElasticaAdapter.php b/lib/Adapter/Elastica/ElasticaAdapter.php index 0586792c..60e467e7 100644 --- a/lib/Adapter/Elastica/ElasticaAdapter.php +++ b/lib/Adapter/Elastica/ElasticaAdapter.php @@ -18,7 +18,7 @@ class ElasticaAdapter implements AdapterInterface { /** - * @phpstan-var int<0, max>|null + * @var int<0, max>|null */ private readonly ?int $maxResults; @@ -53,7 +53,7 @@ public function getResultSet(): ?ResultSet } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -67,8 +67,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Adapter/Elastica/Tests/ElasticaAdapterTest.php b/lib/Adapter/Elastica/Tests/ElasticaAdapterTest.php index 746f83f1..84dfd43f 100644 --- a/lib/Adapter/Elastica/Tests/ElasticaAdapterTest.php +++ b/lib/Adapter/Elastica/Tests/ElasticaAdapterTest.php @@ -48,7 +48,7 @@ public function testConstructorRejectsMaxResultCountLessThanZero(): void public function testGetResultSet(): void { - self::assertNull($this->adapter->getResultSet()); + $this->assertNull($this->adapter->getResultSet()); $this->searchable->method('search') ->with($this->query, ['from' => 0, 'size' => 1, 'option1' => 'value1', 'option2' => 'value2']) @@ -56,7 +56,7 @@ public function testGetResultSet(): void $this->adapter->getSlice(0, 1); - self::assertSame($this->resultSet, $this->adapter->getResultSet()); + $this->assertSame($this->resultSet, $this->adapter->getResultSet()); } public function testGetSlice(): void @@ -67,8 +67,8 @@ public function testGetSlice(): void $resultSet = $this->adapter->getSlice(10, 30); - self::assertSame($this->resultSet, $resultSet); - self::assertSame($this->resultSet, $this->adapter->getResultSet()); + $this->assertSame($this->resultSet, $resultSet); + $this->assertSame($this->resultSet, $this->adapter->getResultSet()); } /** @@ -76,12 +76,12 @@ public function testGetSlice(): void */ public function testGetNbResultsBeforeSearch(): void { - $this->searchable->expects(self::once()) + $this->searchable->expects($this->once()) ->method('count') ->with($this->query) ->willReturn(100); - self::assertSame(100, $this->adapter->getNbResults()); + $this->assertSame(100, $this->adapter->getNbResults()); } /** @@ -91,29 +91,29 @@ public function testGetNbResultsAfterSearch(): void { $adapter = new ElasticaAdapter($this->searchable, $this->query, [], 30); - $this->searchable->expects(self::once()) + $this->searchable->expects($this->once()) ->method('search') ->with($this->query, ['from' => 10, 'size' => 30]) ->willReturn($this->resultSet); - $this->resultSet->expects(self::once()) + $this->resultSet->expects($this->once()) ->method('getTotalHits') ->willReturn(100); $adapter->getSlice(10, 30); - self::assertSame(30, $adapter->getNbResults()); + $this->assertSame(30, $adapter->getNbResults()); } public function testGetNbResultsWithMaxResultsSet(): void { $adapter = new ElasticaAdapter($this->searchable, $this->query, [], 10); - $this->searchable->expects(self::once()) + $this->searchable->expects($this->once()) ->method('count') ->with($this->query) ->willReturn(100); - self::assertSame(10, $adapter->getNbResults()); + $this->assertSame(10, $adapter->getNbResults()); } } diff --git a/lib/Adapter/Solarium/SolariumAdapter.php b/lib/Adapter/Solarium/SolariumAdapter.php index b71464d3..4d1915de 100644 --- a/lib/Adapter/Solarium/SolariumAdapter.php +++ b/lib/Adapter/Solarium/SolariumAdapter.php @@ -22,12 +22,12 @@ class SolariumAdapter implements AdapterInterface private Endpoint|string|null $endpoint = null; /** - * @phpstan-var int<0, max>|null + * @var int<0, max>|null */ private ?int $resultSetStart = null; /** - * @phpstan-var int<0, max>|null + * @var int<0, max>|null */ private ?int $resultSetRows = null; @@ -37,7 +37,7 @@ public function __construct( ) {} /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -45,8 +45,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ @@ -56,8 +56,8 @@ public function getSlice(int $offset, int $length): iterable } /** - * @phpstan-param int<0, max>|null $start - * @phpstan-param int<0, max>|null $rows + * @param int<0, max>|null $start + * @param int<0, max>|null $rows */ public function getResultSet(?int $start = null, ?int $rows = null): Result { @@ -77,8 +77,8 @@ public function getResultSet(?int $start = null, ?int $rows = null): Result } /** - * @phpstan-param int<0, max>|null $start - * @phpstan-param int<0, max>|null $rows + * @param int<0, max>|null $start + * @param int<0, max>|null $rows * * @phpstan-assert-if-true int<0, max> $start * @phpstan-assert-if-true int<0, max> $rows @@ -89,8 +89,8 @@ private function resultSetStartAndRowsAreNotNullAndChange(?int $start, ?int $row } /** - * @phpstan-param int<0, max>|null $start - * @phpstan-param int<0, max>|null $rows + * @param int<0, max>|null $start + * @param int<0, max>|null $rows * * @phpstan-assert-if-true int<0, max> $start * @phpstan-assert-if-true int<0, max> $rows @@ -101,8 +101,8 @@ private function resultSetStartAndRowsAreNotNull(?int $start, ?int $rows): bool } /** - * @phpstan-param int<0, max> $start - * @phpstan-param int<0, max> $rows + * @param int<0, max> $start + * @param int<0, max> $rows */ private function resultSetStartAndRowsChange(int $start, int $rows): bool { diff --git a/lib/Adapter/Solarium/Tests/SolariumAdapterTest.php b/lib/Adapter/Solarium/Tests/SolariumAdapterTest.php index c9fc609c..b7bc9c15 100644 --- a/lib/Adapter/Solarium/Tests/SolariumAdapterTest.php +++ b/lib/Adapter/Solarium/Tests/SolariumAdapterTest.php @@ -45,19 +45,19 @@ public function testGetNbResults(): void $query = $this->createQueryMock(); $result = $this->createResultMock(); - $result->expects(self::once()) + $result->expects($this->once()) ->method('getNumFound') ->willReturn(100); $client = $this->createClientMock(); - $client->expects(self::once()) + $client->expects($this->once()) ->method('select') ->with($query) ->willReturn($result); $adapter = new SolariumAdapter($client, $query); - self::assertSame(100, $adapter->getNbResults()); + $this->assertSame(100, $adapter->getNbResults()); } public function testGetNbResultsCanUseACachedTheResultSet(): void @@ -65,12 +65,12 @@ public function testGetNbResultsCanUseACachedTheResultSet(): void $query = $this->createQueryStub(); $result = $this->createResultMock(); - $result->expects(self::atLeastOnce()) + $result->expects($this->atLeastOnce()) ->method('getNumFound') ->willReturn(200); $client = $this->createClientMock(); - $client->expects(self::once()) + $client->expects($this->once()) ->method('select') ->willReturn($result); @@ -94,14 +94,14 @@ public function testGetSlice(): void $result = $this->createResultMock(); $client = $this->createClientMock(); - $client->expects(self::once()) + $client->expects($this->once()) ->method('select') ->with($query) ->willReturn($result); $adapter = new SolariumAdapter($client, $query); - self::assertSame($result, $adapter->getSlice(1, 200)); + $this->assertSame($result, $adapter->getSlice(1, 200)); } public function testGetSliceCannotUseACachedResultSet(): void @@ -109,7 +109,7 @@ public function testGetSliceCannotUseACachedResultSet(): void $query = $this->createQueryStub(); $result = $this->createResultMock(); - $result->expects(self::atLeastOnce()) + $result->expects($this->atLeastOnce()) ->method('getNumFound') ->willReturn(200); @@ -129,7 +129,7 @@ public function testGetNbResultCanUseAGetSliceCachedResultSet(): void $query = $this->createQueryStub(); $result = $this->createResultMock(); - $result->expects(self::atLeastOnce()) + $result->expects($this->atLeastOnce()) ->method('getNumFound') ->willReturn(200); @@ -187,7 +187,7 @@ public function testGetResultSetCanUseAnEndPoint(): void private function doTestGetResultSet(MockObject&Query $query, Endpoint|string|null $endpoint): void { $client = $this->createClientMock(); - $client->expects(self::atLeastOnce()) + $client->expects($this->atLeastOnce()) ->method('select') ->with($query, $endpoint) ->willReturn($this->createResultMock()); @@ -198,6 +198,6 @@ private function doTestGetResultSet(MockObject&Query $query, Endpoint|string|nul $adapter->setEndpoint($endpoint); } - self::assertInstanceOf(Result::class, $adapter->getResultSet()); + $adapter->getResultSet(); } } diff --git a/lib/Core/Adapter/AdapterInterface.php b/lib/Core/Adapter/AdapterInterface.php index 9775963a..9776c1a7 100644 --- a/lib/Core/Adapter/AdapterInterface.php +++ b/lib/Core/Adapter/AdapterInterface.php @@ -12,7 +12,7 @@ interface AdapterInterface /** * Returns the number of results for the list. * - * @phpstan-return int<0, max> + * @return int<0, max> * * @throws NotValidResultCountException if the number of results is less than zero */ @@ -21,8 +21,8 @@ public function getNbResults(): int; /** * Returns a slice of the results representing the current page of items in the list. * - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Core/Adapter/ArrayAdapter.php b/lib/Core/Adapter/ArrayAdapter.php index 9c4313ae..4a0b6c77 100644 --- a/lib/Core/Adapter/ArrayAdapter.php +++ b/lib/Core/Adapter/ArrayAdapter.php @@ -19,7 +19,7 @@ public function __construct( ) {} /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -27,8 +27,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Core/Adapter/CallbackAdapter.php b/lib/Core/Adapter/CallbackAdapter.php index 06953d8d..5edf0578 100644 --- a/lib/Core/Adapter/CallbackAdapter.php +++ b/lib/Core/Adapter/CallbackAdapter.php @@ -14,22 +14,18 @@ class CallbackAdapter implements AdapterInterface { /** - * @var callable - * - * @phpstan-var callable(): int<0, max> + * @var callable(): int<0, max> */ private $nbResultsCallable; /** - * @var callable - * - * @phpstan-var callable(int<0, max> $offset, int<0, max> $length): iterable + * @var callable(int<0, max> $offset, int<0, max> $length): iterable */ private $sliceCallable; /** - * @phpstan-param callable(): int<0, max> $nbResultsCallable - * @phpstan-param callable(int<0, max> $offset, int<0, max> $length): iterable $sliceCallable + * @param callable(): int<0, max> $nbResultsCallable + * @param callable(int<0, max> $offset, int<0, max> $length): iterable $sliceCallable */ public function __construct(callable $nbResultsCallable, callable $sliceCallable) { @@ -38,7 +34,7 @@ public function __construct(callable $nbResultsCallable, callable $sliceCallable } /** - * @phpstan-return int<0, max> + * @return int<0, max> * * @throws NotValidResultCountException if the number of results is less than zero */ @@ -56,8 +52,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Core/Adapter/ConcatenationAdapter.php b/lib/Core/Adapter/ConcatenationAdapter.php index 546fb51e..ebf47beb 100644 --- a/lib/Core/Adapter/ConcatenationAdapter.php +++ b/lib/Core/Adapter/ConcatenationAdapter.php @@ -28,7 +28,7 @@ class ConcatenationAdapter implements AdapterInterface /** * @param list> $adapters * - * @throws InvalidArgumentException if an adapter is not a `Pagerfanta\Adapter\AdapterInterface` instance + * @throws InvalidArgumentException if an adapter is not a {@see AdapterInterface} instance */ public function __construct(array $adapters) { @@ -42,7 +42,7 @@ public function __construct(array $adapters) } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -56,8 +56,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Core/Adapter/FixedAdapter.php b/lib/Core/Adapter/FixedAdapter.php index 38fc4acc..b7986f93 100644 --- a/lib/Core/Adapter/FixedAdapter.php +++ b/lib/Core/Adapter/FixedAdapter.php @@ -16,7 +16,7 @@ class FixedAdapter implements AdapterInterface { /** - * @phpstan-var int<0, max> + * @var int<0, max> */ private readonly int $nbResults; @@ -37,7 +37,7 @@ public function __construct( } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -45,8 +45,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Core/Adapter/NullAdapter.php b/lib/Core/Adapter/NullAdapter.php index e7b5b72e..38747632 100644 --- a/lib/Core/Adapter/NullAdapter.php +++ b/lib/Core/Adapter/NullAdapter.php @@ -10,14 +10,14 @@ class NullAdapter implements AdapterInterface { /** - * @phpstan-param int<0, max> $nbResults + * @param int<0, max> $nbResults */ public function __construct( private readonly int $nbResults = 0, ) {} /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -30,8 +30,8 @@ public function getNbResults(): int * * Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ @@ -45,10 +45,10 @@ public function getSlice(int $offset, int $length): iterable } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * - * @phpstan-return int<0, max> + * @return int<0, max> */ private function calculateNullArrayLength(int $offset, int $length): int { @@ -62,9 +62,9 @@ private function calculateNullArrayLength(int $offset, int $length): int } /** - * @phpstan-param int<0, max> $offset + * @param int<0, max> $offset * - * @phpstan-return int<0, max> + * @return int<0, max> */ private function remainCount(int $offset): int { @@ -72,7 +72,7 @@ private function remainCount(int $offset): int } /** - * @phpstan-param int<0, max> $length + * @param int<0, max> $length * * @return array */ diff --git a/lib/Core/Adapter/TransformingAdapter.php b/lib/Core/Adapter/TransformingAdapter.php index 7716460d..82c7455b 100644 --- a/lib/Core/Adapter/TransformingAdapter.php +++ b/lib/Core/Adapter/TransformingAdapter.php @@ -6,23 +6,20 @@ * Adapter which transforms the result of other adapter. * * @template T - * @template Transformed + * @template-covariant Transformed * * @implements AdapterInterface */ class TransformingAdapter implements AdapterInterface { /** - * @var callable - * - * @phpstan-var callable(T, array-key): Transformed + * @var callable(T, array-key): Transformed */ private $transformer; /** * @param AdapterInterface $adapter - * - * @phpstan-param callable(T, array-key): Transformed $transformer + * @param callable(T, array-key): Transformed $transformer */ public function __construct( private readonly AdapterInterface $adapter, @@ -32,7 +29,7 @@ public function __construct( } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -40,8 +37,8 @@ public function getNbResults(): int } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length * * @return iterable */ diff --git a/lib/Core/Pagerfanta.php b/lib/Core/Pagerfanta.php index c6931a32..7ec1c41a 100644 --- a/lib/Core/Pagerfanta.php +++ b/lib/Core/Pagerfanta.php @@ -22,27 +22,27 @@ class Pagerfanta implements PagerfantaInterface, \JsonSerializable private bool $normalizeOutOfRangePages = false; /** - * @phpstan-var positive-int + * @var positive-int */ private int $maxPerPage = 10; /** - * @phpstan-var positive-int + * @var positive-int */ private int $currentPage = 1; /** - * @phpstan-var int<0, max>|null + * @var int<0, max>|null */ private ?int $nbResults = null; /** - * @phpstan-var positive-int|null + * @var positive-int|null */ private ?int $maxNbPages = null; /** - * @phpstan-var iterable|null + * @var iterable|null */ private ?iterable $currentPageResults = null; @@ -78,7 +78,9 @@ public function getAdapter(): AdapterInterface } /** - * @return $this + * @return $this + * + * @phpstan-self-out self */ public function setAllowOutOfRangePages(bool $allowOutOfRangePages): PagerfantaInterface { @@ -93,7 +95,9 @@ public function getAllowOutOfRangePages(): bool } /** - * @return $this + * @return $this + * + * @phpstan-self-out self */ public function setNormalizeOutOfRangePages(bool $normalizeOutOfRangePages): PagerfantaInterface { @@ -108,7 +112,9 @@ public function getNormalizeOutOfRangePages(): bool } /** - * @return $this + * @return $this + * + * @phpstan-self-out self * * @throws LessThan1MaxPerPageException if the page is less than 1 */ @@ -147,7 +153,7 @@ private function resetForMaxPerPageChange(): void } /** - * @phpstan-return positive-int + * @return positive-int */ public function getMaxPerPage(): int { @@ -155,7 +161,9 @@ public function getMaxPerPage(): int } /** - * @return $this + * @return $this + * + * @phpstan-self-out self * * @throws LessThan1CurrentPageException if the current page is less than 1 * @throws OutOfRangeCurrentPageException if It is not allowed out of range pages and they are not normalized @@ -169,7 +177,7 @@ public function setCurrentPage(int $currentPage): PagerfantaInterface } /** - * @phpstan-return positive-int + * @return positive-int */ private function filterCurrentPage(int $currentPage): int { @@ -191,9 +199,9 @@ private function checkCurrentPage(int $currentPage): void } /** - * @phpstan-param positive-int $currentPage + * @param positive-int $currentPage * - * @phpstan-return positive-int + * @return positive-int */ private function filterOutOfRangeCurrentPage(int $currentPage): int { @@ -215,7 +223,7 @@ private function currentPageOutOfRange(int $currentPage): bool } /** - * @phpstan-return positive-int + * @return positive-int * * @throws OutOfRangeCurrentPageException if the page should not be normalized */ @@ -234,7 +242,7 @@ private function resetForCurrentPageChange(): void } /** - * @phpstan-return positive-int + * @return positive-int */ public function getCurrentPage(): int { @@ -261,7 +269,7 @@ private function getCurrentPageResultsFromAdapter(): iterable } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ private function calculateOffsetForCurrentPageResults(): int { @@ -269,7 +277,7 @@ private function calculateOffsetForCurrentPageResults(): int } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getCurrentPageOffsetStart(): int { @@ -277,7 +285,7 @@ public function getCurrentPageOffsetStart(): int } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getCurrentPageOffsetEnd(): int { @@ -285,7 +293,7 @@ public function getCurrentPageOffsetEnd(): int } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int { @@ -293,7 +301,7 @@ public function getNbResults(): int } /** - * @phpstan-return positive-int + * @return positive-int */ public function getNbPages(): int { @@ -311,7 +319,7 @@ public function getNbPages(): int } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ private function calculateNbPages(): int { @@ -319,7 +327,7 @@ private function calculateNbPages(): int } /** - * @phpstan-return positive-int + * @return positive-int */ private function minimumNbPages(): int { @@ -327,7 +335,9 @@ private function minimumNbPages(): int } /** - * @return $this + * @return $this + * + * @phpstan-self-out self * * @throws LessThan1MaxPagesException if the max number of pages is less than 1 */ @@ -343,7 +353,9 @@ public function setMaxNbPages(int $maxNbPages): PagerfantaInterface } /** - * @return $this + * @return $this + * + * @phpstan-self-out self */ public function resetMaxNbPages(): PagerfantaInterface { @@ -363,7 +375,7 @@ public function hasPreviousPage(): bool } /** - * @phpstan-return positive-int + * @return positive-int * * @throws LogicException if there is no previous page */ @@ -384,7 +396,7 @@ public function hasNextPage(): bool } /** - * @phpstan-return positive-int + * @return positive-int * * @throws LogicException if there is no next page */ @@ -398,7 +410,7 @@ public function getNextPage(): int } /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function count(): int { @@ -443,9 +455,9 @@ public function jsonSerialize(): array /** * Get page number of the item at specified position (1-based index). * - * @phpstan-param positive-int $position + * @param positive-int $position * - * @phpstan-return positive-int + * @return positive-int * * @throws OutOfBoundsException if the item is outside the result set */ diff --git a/lib/Core/PagerfantaInterface.php b/lib/Core/PagerfantaInterface.php index c557f834..5cd5c5d6 100644 --- a/lib/Core/PagerfantaInterface.php +++ b/lib/Core/PagerfantaInterface.php @@ -24,33 +24,41 @@ interface PagerfantaInterface extends \Countable, \IteratorAggregate public function getAdapter(): AdapterInterface; /** - * @return $this + * @return $this + * + * @phpstan-self-out self */ public function setAllowOutOfRangePages(bool $allowOutOfRangePages): self; public function getAllowOutOfRangePages(): bool; /** - * @return $this + * @return $this + * + * @phpstan-self-out self */ public function setNormalizeOutOfRangePages(bool $normalizeOutOfRangePages): self; public function getNormalizeOutOfRangePages(): bool; /** - * @return $this + * @return $this + * + * @phpstan-self-out self * * @throws LessThan1MaxPerPageException if the page is less than 1 */ public function setMaxPerPage(int $maxPerPage): self; /** - * @phpstan-return positive-int + * @return positive-int */ public function getMaxPerPage(): int; /** - * @return $this + * @return $this + * + * @phpstan-self-out self * * @throws LessThan1CurrentPageException if the current page is less than 1 * @throws OutOfRangeCurrentPageException if It is not allowed out of range pages and they are not normalized @@ -58,7 +66,7 @@ public function getMaxPerPage(): int; public function setCurrentPage(int $currentPage): self; /** - * @phpstan-return positive-int + * @return positive-int */ public function getCurrentPage(): int; @@ -68,34 +76,38 @@ public function getCurrentPage(): int; public function getCurrentPageResults(): iterable; /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getCurrentPageOffsetStart(): int; /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getCurrentPageOffsetEnd(): int; /** - * @phpstan-return int<0, max> + * @return int<0, max> */ public function getNbResults(): int; /** - * @phpstan-return positive-int + * @return positive-int */ public function getNbPages(): int; /** - * @return $this + * @return $this + * + * @phpstan-self-out self * * @throws LessThan1MaxPagesException if the max number of pages is less than 1 */ public function setMaxNbPages(int $maxNbPages): self; /** - * @return $this + * @return $this + * + * @phpstan-self-out self */ public function resetMaxNbPages(): self; @@ -104,7 +116,7 @@ public function haveToPaginate(): bool; public function hasPreviousPage(): bool; /** - * @phpstan-return positive-int + * @return positive-int * * @throws LogicException if there is no previous page */ @@ -113,7 +125,7 @@ public function getPreviousPage(): int; public function hasNextPage(): bool; /** - * @phpstan-return positive-int + * @return positive-int * * @throws LogicException if there is no next page */ @@ -122,9 +134,9 @@ public function getNextPage(): int; /** * Get page number of the item at specified position (1-based index). * - * @phpstan-param positive-int $position + * @param positive-int $position * - * @phpstan-return positive-int + * @return positive-int */ public function getPageNumberForItemAtPosition(int $position): int; } diff --git a/lib/Core/RouteGenerator/RouteGeneratorDecorator.php b/lib/Core/RouteGenerator/RouteGeneratorDecorator.php index 3fa7dd52..39bdfcb7 100644 --- a/lib/Core/RouteGenerator/RouteGeneratorDecorator.php +++ b/lib/Core/RouteGenerator/RouteGeneratorDecorator.php @@ -5,14 +5,12 @@ final class RouteGeneratorDecorator implements RouteGeneratorInterface { /** - * @var callable - * - * @phpstan-var callable(int $page): string + * @var callable(int $page): string */ private $decorated; /** - * @phpstan-param callable(int $page): string $decorated + * @param callable(int $page): string $decorated */ public function __construct(callable $decorated) { diff --git a/lib/Core/Tests/Adapter/ArrayAdapterTest.php b/lib/Core/Tests/Adapter/ArrayAdapterTest.php index be0a460a..a5fd079a 100644 --- a/lib/Core/Tests/Adapter/ArrayAdapterTest.php +++ b/lib/Core/Tests/Adapter/ArrayAdapterTest.php @@ -9,16 +9,12 @@ final class ArrayAdapterTest extends TestCase { /** - * @var list - * - * @phpstan-var list> + * @var list> */ private array $array; /** - * @var ArrayAdapter - * - * @phpstan-var ArrayAdapter> + * @var ArrayAdapter> */ private ArrayAdapter $adapter; @@ -30,9 +26,12 @@ protected function setUp(): void public function testAdapterReturnsNumberOfItemsInArray(): void { - self::assertCount($this->adapter->getNbResults(), $this->array); + $this->assertCount($this->adapter->getNbResults(), $this->array); } + /** + * @return \Generator, 1: int<0, max>}> + */ public static function dataGetSlice(): \Generator { yield [2, 10]; @@ -40,12 +39,12 @@ public static function dataGetSlice(): \Generator } /** - * @phpstan-param int<0, max> $offset - * @phpstan-param int<0, max> $length + * @param int<0, max> $offset + * @param int<0, max> $length */ #[DataProvider('dataGetSlice')] public function testGetSlice(int $offset, int $length): void { - self::assertSame(\array_slice($this->array, $offset, $length), $this->adapter->getSlice($offset, $length)); + $this->assertSame(\array_slice($this->array, $offset, $length), $this->adapter->getSlice($offset, $length)); } } diff --git a/lib/Core/Tests/Adapter/CallbackAdapterTest.php b/lib/Core/Tests/Adapter/CallbackAdapterTest.php index c6b7d394..92ad550d 100644 --- a/lib/Core/Tests/Adapter/CallbackAdapterTest.php +++ b/lib/Core/Tests/Adapter/CallbackAdapterTest.php @@ -17,7 +17,7 @@ public function testAdapterReturnsNumberOfItemsInResultSet(): void static fn (int $offset, int $length) => [] ); - self::assertSame($expected, $adapter->getNbResults()); + $this->assertSame($expected, $adapter->getNbResults()); } public function testAdapterRaisesAnErrorIfTheNumberOfResultsCallableReturnsANegativeNumber(): void @@ -41,7 +41,7 @@ public function testGetSliceShouldReturnTheResultFromTheCallback(): void static fn (int $offset, int $length) => $expected ); - self::assertSame($expected, $adapter->getSlice(1, 1)); + $this->assertSame($expected, $adapter->getSlice(1, 1)); } public function testGetSliceShouldPassTheOffsetAndLengthToTheGetSliceCallback(): void diff --git a/lib/Core/Tests/Adapter/ConcatenationAdapterTest.php b/lib/Core/Tests/Adapter/ConcatenationAdapterTest.php index 8fc64b41..9c4bdaed 100644 --- a/lib/Core/Tests/Adapter/ConcatenationAdapterTest.php +++ b/lib/Core/Tests/Adapter/ConcatenationAdapterTest.php @@ -42,7 +42,7 @@ public function testGetNbResultsFromSingleAdapter(): void new ArrayAdapter(['foo', 'bar', 'baz']), ]); - self::assertSame(3, $adapter->getNbResults()); + $this->assertSame(3, $adapter->getNbResults()); } public function testGetNbResultsFromMultipleAdapters(): void @@ -53,13 +53,13 @@ public function testGetNbResultsFromMultipleAdapters(): void new ArrayAdapter(['baq']), ]); - self::assertSame(11, $adapter->getNbResults()); + $this->assertSame(11, $adapter->getNbResults()); } public function testGetNbResultsWithNoAdapters(): void { $adapter = new ConcatenationAdapter([]); - self::assertSame(0, $adapter->getNbResults()); + $this->assertSame(0, $adapter->getNbResults()); } public function testGetResults(): void @@ -69,10 +69,10 @@ public function testGetResults(): void new ArrayAdapter([7, 8, 9, 10, 11, 12, 13, 14]), new ArrayAdapter([15, 16, 17]), ]); - self::assertSame([8, 9, 10], $adapter->getSlice(7, 3)); - self::assertSame([5, 6, 7, 8], $adapter->getSlice(4, 4)); - self::assertSame([6, 7, 8, 9, 10, 11, 12, 13, 14, 15], $adapter->getSlice(5, 10)); - self::assertSame([16, 17], $adapter->getSlice(15, 5)); + $this->assertSame([8, 9, 10], $adapter->getSlice(7, 3)); + $this->assertSame([5, 6, 7, 8], $adapter->getSlice(4, 4)); + $this->assertSame([6, 7, 8, 9, 10, 11, 12, 13, 14, 15], $adapter->getSlice(5, 10)); + $this->assertSame([16, 17], $adapter->getSlice(15, 5)); } public function testGetResultsWithTraversableAdapter(): void @@ -88,7 +88,7 @@ public function testGetResultsWithTraversableAdapter(): void ), ]); - self::assertSame([2, 3], $adapter->getSlice(1, 2)); - self::assertSame([4, 5, 6], $adapter->getSlice(3, 3)); + $this->assertSame([2, 3], $adapter->getSlice(1, 2)); + $this->assertSame([4, 5, 6], $adapter->getSlice(3, 3)); } } diff --git a/lib/Core/Tests/Adapter/EmptyAdapterTest.php b/lib/Core/Tests/Adapter/EmptyAdapterTest.php index 0de32633..e30217d9 100644 --- a/lib/Core/Tests/Adapter/EmptyAdapterTest.php +++ b/lib/Core/Tests/Adapter/EmptyAdapterTest.php @@ -11,13 +11,13 @@ public function testGetNbResults(): void { $adapter = new EmptyAdapter(); - self::assertSame(0, $adapter->getNbResults()); + $this->assertSame(0, $adapter->getNbResults()); } public function testGetSliceShouldReturnAnEmptyArray(): void { $adapter = new EmptyAdapter(); - self::assertSame([], $adapter->getSlice(10, 5)); + $this->assertSame([], $adapter->getSlice(10, 5)); } } diff --git a/lib/Core/Tests/Adapter/FixedAdapterTest.php b/lib/Core/Tests/Adapter/FixedAdapterTest.php index 077182cc..5652ff45 100644 --- a/lib/Core/Tests/Adapter/FixedAdapterTest.php +++ b/lib/Core/Tests/Adapter/FixedAdapterTest.php @@ -20,7 +20,7 @@ public function testGetNbResults(): void { $adapter = new FixedAdapter(5, []); - self::assertSame(5, $adapter->getNbResults()); + $this->assertSame(5, $adapter->getNbResults()); } public static function dataGetSlice(): \Generator @@ -34,7 +34,7 @@ public function testGetSlice(iterable $results): void { $adapter = new FixedAdapter(5, $results); - self::assertSame($results, $adapter->getSlice(0, 10)); - self::assertSame($results, $adapter->getSlice(10, 20)); + $this->assertSame($results, $adapter->getSlice(0, 10)); + $this->assertSame($results, $adapter->getSlice(10, 20)); } } diff --git a/lib/Core/Tests/Adapter/NullAdapterTest.php b/lib/Core/Tests/Adapter/NullAdapterTest.php index 092396dd..001e7384 100644 --- a/lib/Core/Tests/Adapter/NullAdapterTest.php +++ b/lib/Core/Tests/Adapter/NullAdapterTest.php @@ -11,41 +11,41 @@ public function testGetNbResults(): void { $adapter = new NullAdapter(33); - self::assertSame(33, $adapter->getNbResults()); + $this->assertSame(33, $adapter->getNbResults()); } public function testGetSliceShouldReturnAnEmptyArrayIfTheOffsetIsEqualThanTheNbResults(): void { $adapter = new NullAdapter(10); - self::assertSame([], $adapter->getSlice(10, 5)); + $this->assertSame([], $adapter->getSlice(10, 5)); } public function testGetSliceShouldReturnAnEmptyArrayIfTheOffsetIsGreaterThanTheNbResults(): void { $adapter = new NullAdapter(10); - self::assertSame([], $adapter->getSlice(11, 5)); + $this->assertSame([], $adapter->getSlice(11, 5)); } public function testGetSliceShouldReturnANullArrayWithTheLengthPassed(): void { $adapter = new NullAdapter(100); - self::assertSame($this->createNullArray(10), $adapter->getSlice(20, 10)); + $this->assertSame($this->createNullArray(10), $adapter->getSlice(20, 10)); } public function testGetSliceShouldReturnANullArrayWithTheRemainCountWhenLengthIsGreaterThanTheRemain(): void { $adapter = new NullAdapter(33); - self::assertSame($this->createNullArray(3), $adapter->getSlice(30, 10)); + $this->assertSame($this->createNullArray(3), $adapter->getSlice(30, 10)); } /** - * @phpstan-param int<0, max> $length + * @param int<0, max> $length * - * @phpstan-return array + * @return array */ private function createNullArray(int $length): array { diff --git a/lib/Core/Tests/Adapter/TransformingAdapterTest.php b/lib/Core/Tests/Adapter/TransformingAdapterTest.php index c8b49f4d..514fcccb 100644 --- a/lib/Core/Tests/Adapter/TransformingAdapterTest.php +++ b/lib/Core/Tests/Adapter/TransformingAdapterTest.php @@ -9,16 +9,12 @@ final class TransformingAdapterTest extends TestCase { /** - * @var list - * - * @phpstan-var list> + * @var list> */ private array $array; /** - * @var TransformingAdapter - * - * @phpstan-var TransformingAdapter, string> + * @var TransformingAdapter, string> */ private TransformingAdapter $adapter; @@ -33,12 +29,12 @@ protected function setUp(): void public function testAdapterReturnsNumberOfItemsInArray(): void { - self::assertCount($this->adapter->getNbResults(), $this->array); + $this->assertCount($this->adapter->getNbResults(), $this->array); } public function testGetSlice(): void { - self::assertSame(['0 => 4', '1 => 5'], [...$this->adapter->getSlice(3, 2)]); + $this->assertSame(['0 => 4', '1 => 5'], [...$this->adapter->getSlice(3, 2)]); } public function testCreateFromInvokable(): void @@ -53,6 +49,6 @@ public function __invoke(int $item, int $key): string } ); - self::assertSame(['-89', '-88', '-87', '-86', '-85'], [...$this->adapter->getSlice(10, 5)]); + $this->assertSame(['-89', '-88', '-87', '-86', '-85'], [...$this->adapter->getSlice(10, 5)]); } } diff --git a/lib/Core/Tests/PagerfantaTest.php b/lib/Core/Tests/PagerfantaTest.php index 5488664e..52f42d02 100644 --- a/lib/Core/Tests/PagerfantaTest.php +++ b/lib/Core/Tests/PagerfantaTest.php @@ -31,6 +31,9 @@ protected function setUp(): void $this->pagerfanta = new Pagerfanta($this->adapter); } + /** + * @return \Generator}> + */ public static function dataCountsAsIntegers(): \Generator { yield '1 item' => [1]; @@ -38,6 +41,9 @@ public static function dataCountsAsIntegers(): \Generator yield '25 items' => [25]; } + /** + * @return \Generator + */ public static function dataCountsAsNonIntegers(): \Generator { yield 'float' => [1.1]; @@ -46,6 +52,9 @@ public static function dataCountsAsNonIntegers(): \Generator yield 'array' => [[1]]; } + /** + * @return \Generator + */ public static function dataLessThan1(): \Generator { yield 'zero' => [0]; @@ -54,51 +63,51 @@ public static function dataLessThan1(): \Generator public function testTheStaticConstructorCreatesAPagerfantaInstance(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); $pagerfanta = Pagerfanta::createForCurrentPageWithMaxPerPage($this->adapter, 2, 5); - self::assertSame(2, $pagerfanta->getCurrentPage()); - self::assertSame(5, $pagerfanta->getMaxPerPage()); + $this->assertSame(2, $pagerfanta->getCurrentPage()); + $this->assertSame(5, $pagerfanta->getMaxPerPage()); } public function testTheAdapterCanBeRetrieved(): void { - self::assertSame($this->adapter, $this->pagerfanta->getAdapter()); + $this->assertSame($this->adapter, $this->pagerfanta->getAdapter()); } public function testThePagerCanAllowOutOfRangePages(): void { - self::assertSame($this->pagerfanta, $this->pagerfanta->setAllowOutOfRangePages(true), 'setAllowOutOfRangePages has a fluent interface'); - self::assertTrue($this->pagerfanta->getAllowOutOfRangePages()); + $this->assertSame($this->pagerfanta, $this->pagerfanta->setAllowOutOfRangePages(true), 'setAllowOutOfRangePages has a fluent interface'); + $this->assertTrue($this->pagerfanta->getAllowOutOfRangePages()); } public function testOutOfRangePagesIsDisallowedByDefault(): void { - self::assertFalse($this->pagerfanta->getAllowOutOfRangePages()); + $this->assertFalse($this->pagerfanta->getAllowOutOfRangePages()); } public function testThePagerCanNormalizeOutOfRangePages(): void { - self::assertSame($this->pagerfanta, $this->pagerfanta->setNormalizeOutOfRangePages(true), 'setNormalizeOutOfRangePages has a fluent interface'); - self::assertTrue($this->pagerfanta->getNormalizeOutOfRangePages()); + $this->assertSame($this->pagerfanta, $this->pagerfanta->setNormalizeOutOfRangePages(true), 'setNormalizeOutOfRangePages has a fluent interface'); + $this->assertTrue($this->pagerfanta->getNormalizeOutOfRangePages()); } public function testNormalizingOutOfRangePagesIsDisallowedByDefault(): void { - self::assertFalse($this->pagerfanta->getNormalizeOutOfRangePages()); + $this->assertFalse($this->pagerfanta->getNormalizeOutOfRangePages()); } /** - * @phpstan-param positive-int $maxPerPage + * @param positive-int $maxPerPage */ #[DataProvider('dataCountsAsIntegers')] public function testTheMaximumNumberOfItemsPerPageCanBeSet(int $maxPerPage): void { - self::assertSame($this->pagerfanta, $this->pagerfanta->setMaxPerPage($maxPerPage), 'setMaxPerPage has a fluent interface'); - self::assertSame($maxPerPage, $this->pagerfanta->getMaxPerPage()); + $this->assertSame($this->pagerfanta, $this->pagerfanta->setMaxPerPage($maxPerPage), 'setMaxPerPage has a fluent interface'); + $this->assertSame($maxPerPage, $this->pagerfanta->getMaxPerPage()); } #[DataProvider('dataLessThan1')] @@ -115,7 +124,7 @@ public function testSetMaxPerPageAfterCurrentPageShouldThrowExceptionOutOfRange( $this->pagerfanta->setCurrentPage(3); $this->pagerfanta->setAllowOutOfRangePages(false); - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(20); $this->pagerfanta->setMaxPerPage(10); @@ -130,40 +139,40 @@ public function testSetMaxPerPageShouldResetCurrentPageResults(): void public function testSetMaxPerPageShouldNotResetNbResults(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); - self::assertSame(100, $this->pagerfanta->getNbResults()); + $this->assertSame(100, $this->pagerfanta->getNbResults()); $this->pagerfanta->setMaxPerPage(5); - self::assertSame(100, $this->pagerfanta->getNbResults()); + $this->assertSame(100, $this->pagerfanta->getNbResults()); } public function testSetMaxPerPageShouldResetNbPages(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); - self::assertSame(10, $this->pagerfanta->getNbPages()); + $this->assertSame(10, $this->pagerfanta->getNbPages()); $this->pagerfanta->setMaxPerPage(20); - self::assertSame(5, $this->pagerfanta->getNbPages()); + $this->assertSame(5, $this->pagerfanta->getNbPages()); } public function testTheNumberOfResultsAreRetrievedFromTheAdapter(): void { $results = 20; - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn($results); - self::assertSame($results, $this->pagerfanta->getNbResults()); + $this->assertSame($results, $this->pagerfanta->getNbResults()); } public function testGetNbResultsShouldCacheTheNbResultsFromTheAdapter(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(20); @@ -173,52 +182,52 @@ public function testGetNbResultsShouldCacheTheNbResultsFromTheAdapter(): void public function testGetNbPagesShouldCalculateTheNumberOfPages(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); $this->pagerfanta->setMaxPerPage(20); - self::assertSame(5, $this->pagerfanta->getNbPages()); + $this->assertSame(5, $this->pagerfanta->getNbPages()); } public function testGetNbPagesShouldRoundUpToTheNextPage(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); $this->pagerfanta->setMaxPerPage(15); - self::assertSame(7, $this->pagerfanta->getNbPages()); + $this->assertSame(7, $this->pagerfanta->getNbPages()); } public function testThereShouldBeOnePageWhenThereAreNoResults(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(0); - self::assertSame(1, $this->pagerfanta->getNbPages()); + $this->assertSame(1, $this->pagerfanta->getNbPages()); } public function testTheMaximumNumberPagesCanBeSetAndReset(): void { // Fake 10 pages being expected - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); $originalPageCount = $this->pagerfanta->getNbPages(); - self::assertSame($this->pagerfanta, $this->pagerfanta->setMaxNbPages(5), 'setMaxNbPages has a fluent interface'); - self::assertSame(5, $this->pagerfanta->getNbPages(), 'The configured maximum number of pages should be used'); + $this->assertSame($this->pagerfanta, $this->pagerfanta->setMaxNbPages(5), 'setMaxNbPages has a fluent interface'); + $this->assertSame(5, $this->pagerfanta->getNbPages(), 'The configured maximum number of pages should be used'); - self::assertSame($this->pagerfanta, $this->pagerfanta->setMaxNbPages(15), 'setMaxNbPages has a fluent interface'); - self::assertSame($originalPageCount, $this->pagerfanta->getNbPages(), 'When the configured maximum number of pages is less than the real number of pages, then the number of pages should be used'); + $this->assertSame($this->pagerfanta, $this->pagerfanta->setMaxNbPages(15), 'setMaxNbPages has a fluent interface'); + $this->assertSame($originalPageCount, $this->pagerfanta->getNbPages(), 'When the configured maximum number of pages is less than the real number of pages, then the number of pages should be used'); - self::assertSame($this->pagerfanta, $this->pagerfanta->resetMaxNbPages(), 'resetMaxNbPages has a fluent interface'); - self::assertSame($originalPageCount, $this->pagerfanta->getNbPages(), 'When there is no maximum number of pages configured, then the number of pages should be used'); + $this->assertSame($this->pagerfanta, $this->pagerfanta->resetMaxNbPages(), 'resetMaxNbPages has a fluent interface'); + $this->assertSame($originalPageCount, $this->pagerfanta->getNbPages(), 'When there is no maximum number of pages configured, then the number of pages should be used'); } #[DataProvider('dataLessThan1')] @@ -230,21 +239,21 @@ public function testSetMaxNbPagesShouldThrowExceptionWhenLessThan1(int $maxPages } /** - * @phpstan-param positive-int $currentPage + * @param positive-int $currentPage */ #[DataProvider('dataCountsAsIntegers')] public function testTheCurrentPageNumberCanBeSet(int $currentPage): void { if ($currentPage > 1) { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); } $this->pagerfanta->setMaxPerPage(2); - self::assertSame($this->pagerfanta, $this->pagerfanta->setCurrentPage($currentPage), 'setCurrentPage has a fluent interface'); + $this->assertSame($this->pagerfanta, $this->pagerfanta->setCurrentPage($currentPage), 'setCurrentPage has a fluent interface'); - self::assertSame($currentPage, $this->pagerfanta->getCurrentPage()); + $this->assertSame($currentPage, $this->pagerfanta->getCurrentPage()); } #[DataProvider('dataLessThan1')] @@ -259,7 +268,7 @@ public function testSetCurrentPageShouldThrowExceptionWhenThePageIsOutOfRange(): { $this->expectException(OutOfRangeCurrentPageException::class); - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); @@ -273,7 +282,7 @@ public function testSetCurrentPageShouldNotThrowExceptionWhenOutOfRangePagesAreA $this->pagerfanta->setAllowOutOfRangePages(true); $this->pagerfanta->setCurrentPage(11); - self::assertSame(11, $this->pagerfanta->getCurrentPage()); + $this->assertSame(11, $this->pagerfanta->getCurrentPage()); } public function testSetCurrentPageShouldResetCurrentPageResults(): void @@ -283,6 +292,9 @@ public function testSetCurrentPageShouldResetCurrentPageResults(): void }); } + /** + * @return \Generator}> + */ public static function dataGetCurrentPageResultSizes(): \Generator { // max per page, current page, offset @@ -292,15 +304,15 @@ public static function dataGetCurrentPageResultSizes(): \Generator } /** - * @phpstan-param positive-int $maxPerPage - * @phpstan-param positive-int $currentPage - * @phpstan-param int<0, max> $offset + * @param positive-int $maxPerPage + * @param positive-int $currentPage + * @param int<0, max> $offset */ #[DataProvider('dataGetCurrentPageResultSizes')] public function testGetCurrentPageResultsShouldReturnASliceFromTheAdapterForTheCurrentPageWithCorrectSizeAndCacheTheResults(int $maxPerPage, int $currentPage, int $offset): void { if ($currentPage > 1) { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); } @@ -310,63 +322,66 @@ public function testGetCurrentPageResultsShouldReturnASliceFromTheAdapterForTheC $currentPageResults = new \ArrayObject(); - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getSlice') ->with($offset, $maxPerPage) ->willReturn($currentPageResults); - self::assertSame($currentPageResults, $this->pagerfanta->getCurrentPageResults()); - self::assertSame($currentPageResults, $this->pagerfanta->getCurrentPageResults()); + $this->assertSame($currentPageResults, $this->pagerfanta->getCurrentPageResults()); + $this->assertSame($currentPageResults, $this->pagerfanta->getCurrentPageResults()); } public function testTheCurrentPageOffsetStartIsRetrieved(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); $this->pagerfanta->setMaxPerPage(10); $this->pagerfanta->setCurrentPage(2); - self::assertSame(11, $this->pagerfanta->getCurrentPageOffsetStart()); + $this->assertSame(11, $this->pagerfanta->getCurrentPageOffsetStart()); } public function testTheCurrentPageOffsetStartIsRetrievedWhenThereAreNoResults(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(0); $this->pagerfanta->setMaxPerPage(10); $this->pagerfanta->setCurrentPage(1); - self::assertSame(0, $this->pagerfanta->getCurrentPageOffsetStart()); + $this->assertSame(0, $this->pagerfanta->getCurrentPageOffsetStart()); } public function testTheCurrentPageOffsetEndIsRetrieved(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); $this->pagerfanta->setMaxPerPage(10); $this->pagerfanta->setCurrentPage(2); - self::assertSame(20, $this->pagerfanta->getCurrentPageOffsetEnd()); + $this->assertSame(20, $this->pagerfanta->getCurrentPageOffsetEnd()); } public function testTheCurrentPageOffsetEndIsRetrievedWhenOnTheLastPage(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(90); $this->pagerfanta->setMaxPerPage(20); $this->pagerfanta->setCurrentPage(5); - self::assertSame(90, $this->pagerfanta->getCurrentPageOffsetEnd()); + $this->assertSame(90, $this->pagerfanta->getCurrentPageOffsetEnd()); } + /** + * @return \Generator}> + */ public static function dataHaveToPaginate(): \Generator { yield 'does paginate when number of results is greater than the maximum items per page' => [true, 99, 100]; @@ -375,45 +390,45 @@ public static function dataHaveToPaginate(): \Generator } /** - * @phpstan-param positive-int $maxPerPage - * @phpstan-param int<0, max> $nbResults + * @param positive-int $maxPerPage + * @param int<0, max> $nbResults */ #[DataProvider('dataHaveToPaginate')] public function testHaveToPaginateReportsCorrectly(bool $expected, int $maxPerPage, int $nbResults): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn($nbResults); $this->pagerfanta->setMaxPerPage($maxPerPage); - self::assertSame($expected, $this->pagerfanta->haveToPaginate()); + $this->assertSame($expected, $this->pagerfanta->haveToPaginate()); } public function testHasPreviousPageReportsCorrectly(): void { - $this->adapter->expects(self::atLeastOnce()) + $this->adapter->expects($this->atLeastOnce()) ->method('getNbResults') ->willReturn(100); $this->pagerfanta->setCurrentPage(1); - self::assertFalse($this->pagerfanta->hasPreviousPage()); + $this->assertFalse($this->pagerfanta->hasPreviousPage()); for ($page = 2; $page <= $this->pagerfanta->getNbPages(); ++$page) { $this->pagerfanta->setCurrentPage($page); - self::assertTrue($this->pagerfanta->hasPreviousPage()); + $this->assertTrue($this->pagerfanta->hasPreviousPage()); } } public function testGetPreviousPageShouldReturnThePreviousPage(): void { - $this->adapter->expects(self::atLeastOnce()) + $this->adapter->expects($this->atLeastOnce()) ->method('getNbResults') ->willReturn(100); for ($page = 2; $page <= $this->pagerfanta->getNbPages(); ++$page) { $this->pagerfanta->setCurrentPage($page); - self::assertSame($page - 1, $this->pagerfanta->getPreviousPage()); + $this->assertSame($page - 1, $this->pagerfanta->getPreviousPage()); } } @@ -426,28 +441,28 @@ public function testGetPreviousPageShouldThrowALogicExceptionIfThereIsNoPrevious public function testHasNextPageReportsCorrectly(): void { - $this->adapter->expects(self::atLeastOnce()) + $this->adapter->expects($this->atLeastOnce()) ->method('getNbResults') ->willReturn(100); for ($page = 1; $page < $this->pagerfanta->getNbPages(); ++$page) { $this->pagerfanta->setCurrentPage($page); - self::assertTrue($this->pagerfanta->hasNextPage()); + $this->assertTrue($this->pagerfanta->hasNextPage()); } $this->pagerfanta->setCurrentPage($this->pagerfanta->getNbPages()); - self::assertFalse($this->pagerfanta->hasNextPage()); + $this->assertFalse($this->pagerfanta->hasNextPage()); } public function testGetNextPageShouldReturnTheNextPage(): void { - $this->adapter->expects(self::atLeastOnce()) + $this->adapter->expects($this->atLeastOnce()) ->method('getNbResults') ->willReturn(100); for ($page = 1; $page < $this->pagerfanta->getNbPages(); ++$page) { $this->pagerfanta->setCurrentPage($page); - self::assertSame($page + 1, $this->pagerfanta->getNextPage()); + $this->assertSame($page + 1, $this->pagerfanta->getNextPage()); } } @@ -455,7 +470,7 @@ public function testGetNextPageShouldThrowALogicExceptionIfTheCurrentPageIsTheLa { $this->expectException(LogicException::class); - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); @@ -466,11 +481,11 @@ public function testGetNextPageShouldThrowALogicExceptionIfTheCurrentPageIsTheLa public function testThePagerCanBeCounted(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); - self::assertCount(100, $this->pagerfanta); + $this->assertCount(100, $this->pagerfanta); } public function testThePagerCanBeIteratedWithTheCurrentPageResultsWhenTheAdapterReturnsAnIterator(): void @@ -478,11 +493,11 @@ public function testThePagerCanBeIteratedWithTheCurrentPageResultsWhenTheAdapter /** @var MockObject&\Iterator $currentPageResults */ $currentPageResults = $this->createMock(\Iterator::class); - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getSlice') ->willReturn($currentPageResults); - self::assertSame($currentPageResults, $this->pagerfanta->getIterator()); + $this->assertSame($currentPageResults, $this->pagerfanta->getIterator()); } public function testThePagerCanBeIteratedWithTheCurrentPageResultsWhenTheAdapterReturnsAnIteratorAggregate(): void @@ -491,35 +506,35 @@ public function testThePagerCanBeIteratedWithTheCurrentPageResultsWhenTheAdapter /** @var MockObject&\IteratorAggregate $currentPageResults */ $currentPageResults = $this->createMock(\IteratorAggregate::class); - $currentPageResults->expects(self::once()) + $currentPageResults->expects($this->once()) ->method('getIterator') ->willReturn($iterator); - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getSlice') ->willReturn($currentPageResults); - self::assertSame($iterator, $this->pagerfanta->getIterator()); + $this->assertSame($iterator, $this->pagerfanta->getIterator()); } public function testThePagerCanBeIteratedWithTheCurrentPageResultsWhenTheAdapterReturnsAnArray(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getSlice') ->willReturn([]); - self::assertInstanceOf(\ArrayIterator::class, $this->pagerfanta->getIterator()); + $this->assertInstanceOf(\ArrayIterator::class, $this->pagerfanta->getIterator()); } public function testThePagerCanBeJsonEncodedWithTheCurrentPageResultsWhenTheAdapterReturnsAnArray(): void { $pageResults = ['foo', 'bar']; - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getSlice') ->willReturn($pageResults); - self::assertJsonStringEqualsJsonString(json_encode($pageResults, \JSON_THROW_ON_ERROR), json_encode($this->pagerfanta, \JSON_THROW_ON_ERROR)); + $this->assertJsonStringEqualsJsonString(json_encode($pageResults, \JSON_THROW_ON_ERROR), json_encode($this->pagerfanta, \JSON_THROW_ON_ERROR)); } public function testThePagerCanBeJsonEncodedWithTheCurrentPageResultsWhenTheAdapterReturnsATraversable(): void @@ -530,17 +545,20 @@ public function testThePagerCanBeJsonEncodedWithTheCurrentPageResultsWhenTheAdap /** @var MockObject&\IteratorAggregate $currentPageResults */ $currentPageResults = $this->createMock(\IteratorAggregate::class); - $currentPageResults->expects(self::once()) + $currentPageResults->expects($this->once()) ->method('getIterator') ->willReturn($iterator); - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getSlice') ->willReturn($currentPageResults); - self::assertJsonStringEqualsJsonString(json_encode($pageResults, \JSON_THROW_ON_ERROR), json_encode($this->pagerfanta, \JSON_THROW_ON_ERROR)); + $this->assertJsonStringEqualsJsonString(json_encode($pageResults, \JSON_THROW_ON_ERROR), json_encode($this->pagerfanta, \JSON_THROW_ON_ERROR)); } + /** + * @return \Generator + */ public static function dataGetPageNumberForItemAtPosition(): \Generator { yield 'position 10' => [1, 10]; @@ -548,23 +566,23 @@ public static function dataGetPageNumberForItemAtPosition(): \Generator } /** - * @phpstan-param positive-int $position + * @param positive-int $position */ #[DataProvider('dataGetPageNumberForItemAtPosition')] public function testGetPageNumberForItemAtPosition(int $page, int $position): void { - $this->adapter->expects(self::atLeastOnce()) + $this->adapter->expects($this->atLeastOnce()) ->method('getNbResults') ->willReturn(100); - self::assertSame($page, $this->pagerfanta->getPageNumberForItemAtPosition($position)); + $this->assertSame($page, $this->pagerfanta->getPageNumberForItemAtPosition($position)); } public function testGetPageNumberForItemAtPositionShouldThrowAnExceptionIfTheItemIsMoreThanNbPages(): void { $this->expectException(\OutOfBoundsException::class); - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(100); @@ -573,7 +591,7 @@ public function testGetPageNumberForItemAtPositionShouldThrowAnExceptionIfTheIte public function testAutoPagingIterator(): void { - $this->adapter->expects(self::once()) + $this->adapter->expects($this->once()) ->method('getNbResults') ->willReturn(3); @@ -583,16 +601,16 @@ public function testAutoPagingIterator(): void ->method('getSlice') ->willReturnCallback(function (int $offset, int $length) use ($matcher): array { if (1 === $matcher->numberOfInvocations()) { - TestCase::assertSame($offset, 0); - TestCase::assertSame($length, 2); + TestCase::assertSame(0, $offset); + TestCase::assertSame(2, $length); return [ ['id' => 1], ['id' => 2], ]; } elseif (2 === $matcher->numberOfInvocations()) { - TestCase::assertSame($offset, 2); - TestCase::assertSame($length, 2); + TestCase::assertSame(2, $offset); + TestCase::assertSame(2, $length); return [ ['id' => 3], @@ -613,7 +631,7 @@ public function testAutoPagingIterator(): void $seen[] = $value['id']; } - self::assertSame([1, 2, 3], $seen); + $this->assertSame([1, 2, 3], $seen); } private function resetCurrentPageResults(callable $callback): void @@ -630,8 +648,8 @@ private function resetCurrentPageResults(callable $callback): void $currentPageResults1 ); - self::assertSame($currentPageResults0, $this->pagerfanta->getCurrentPageResults()); + $this->assertSame($currentPageResults0, $this->pagerfanta->getCurrentPageResults()); $callback(); - self::assertSame($currentPageResults1, $this->pagerfanta->getCurrentPageResults()); + $this->assertSame($currentPageResults1, $this->pagerfanta->getCurrentPageResults()); } } diff --git a/lib/Core/Tests/View/OptionableViewTest.php b/lib/Core/Tests/View/OptionableViewTest.php index 974c76c6..2cc69a68 100644 --- a/lib/Core/Tests/View/OptionableViewTest.php +++ b/lib/Core/Tests/View/OptionableViewTest.php @@ -29,7 +29,7 @@ protected function setUp(): void } /** - * @phpstan-return \Closure(int $page): string + * @return \Closure(int $page): string */ private function createRouteGenerator(): \Closure { @@ -40,7 +40,7 @@ public function testRenderShouldDelegateToTheView(): void { $defaultOptions = ['foo' => 'bar', 'bar' => 'ups']; - self::assertSame(self::RENDERED_VIEW, (new OptionableView($this->createViewMock($defaultOptions), $defaultOptions))->render($this->pagerfanta, $this->routeGenerator)); + $this->assertSame(self::RENDERED_VIEW, (new OptionableView($this->createViewMock($defaultOptions), $defaultOptions))->render($this->pagerfanta, $this->routeGenerator)); } public function testRenderShouldMergeOptions(): void @@ -48,14 +48,14 @@ public function testRenderShouldMergeOptions(): void $defaultOptions = ['foo' => 'bar']; $options = ['ups' => 'da']; - self::assertSame(self::RENDERED_VIEW, (new OptionableView($this->createViewMock([...$defaultOptions, ...$options]), $defaultOptions))->render($this->pagerfanta, $this->routeGenerator, $options)); + $this->assertSame(self::RENDERED_VIEW, (new OptionableView($this->createViewMock([...$defaultOptions, ...$options]), $defaultOptions))->render($this->pagerfanta, $this->routeGenerator, $options)); } private function createViewMock(array $expectedOptions): MockObject&ViewInterface { /** @var MockObject&ViewInterface $view */ $view = $this->createMock(ViewInterface::class); - $view->expects(self::once()) + $view->expects($this->once()) ->method('render') ->with($this->pagerfanta, $this->routeGenerator, $expectedOptions) ->willReturn(self::RENDERED_VIEW); diff --git a/lib/Core/Tests/View/ViewFactoryTest.php b/lib/Core/Tests/View/ViewFactoryTest.php index ea54cf52..f795f52b 100644 --- a/lib/Core/Tests/View/ViewFactoryTest.php +++ b/lib/Core/Tests/View/ViewFactoryTest.php @@ -29,31 +29,31 @@ public function testFactory(): void $factory->set('foo', $view1); $factory->set('bar', $view2); - self::assertSame(['foo' => $view1, 'bar' => $view2], $factory->all()); + $this->assertSame(['foo' => $view1, 'bar' => $view2], $factory->all()); - self::assertSame($view1, $factory->get('foo')); - self::assertSame($view2, $factory->get('bar')); + $this->assertSame($view1, $factory->get('foo')); + $this->assertSame($view2, $factory->get('bar')); try { $factory->get('foobar'); self::fail('The view factory should raise an exception if an unknown view is requested'); } catch (\Exception $e) { - self::assertInstanceOf(InvalidArgumentException::class, $e); + $this->assertInstanceOf(InvalidArgumentException::class, $e); } - self::assertTrue($factory->has('foo')); - self::assertTrue($factory->has('bar')); - self::assertFalse($factory->has('foobar')); + $this->assertTrue($factory->has('foo')); + $this->assertTrue($factory->has('bar')); + $this->assertFalse($factory->has('foobar')); $factory->add([ 'ups' => $view3, 'man' => $view4, ]); - self::assertSame($view3, $factory->get('ups')); - self::assertSame($view4, $factory->get('man')); - self::assertTrue($factory->has('ups')); - self::assertTrue($factory->has('man')); - self::assertSame([ + $this->assertSame($view3, $factory->get('ups')); + $this->assertSame($view4, $factory->get('man')); + $this->assertTrue($factory->has('ups')); + $this->assertTrue($factory->has('man')); + $this->assertSame([ 'foo' => $view1, 'bar' => $view2, 'ups' => $view3, @@ -61,17 +61,17 @@ public function testFactory(): void ], $factory->all()); $factory->remove('bar'); - self::assertFalse($factory->has('bar')); - self::assertTrue($factory->has('foo')); - self::assertTrue($factory->has('ups')); - self::assertTrue($factory->has('man')); - self::assertSame([ + $this->assertFalse($factory->has('bar')); + $this->assertTrue($factory->has('foo')); + $this->assertTrue($factory->has('ups')); + $this->assertTrue($factory->has('man')); + $this->assertSame([ 'foo' => $view1, 'ups' => $view3, 'man' => $view4, ], $factory->all()); $factory->clear(); - self::assertSame([], $factory->all()); + $this->assertSame([], $factory->all()); } } diff --git a/lib/Core/Tests/View/ViewTestCase.php b/lib/Core/Tests/View/ViewTestCase.php index 4f1443f6..3a6bb08b 100644 --- a/lib/Core/Tests/View/ViewTestCase.php +++ b/lib/Core/Tests/View/ViewTestCase.php @@ -46,7 +46,7 @@ private function calculateNbResults(int $nbPages): int } /** - * @phpstan-param positive-int $currentPage + * @param positive-int $currentPage */ protected function setCurrentPage(int $currentPage): void { @@ -64,7 +64,7 @@ protected function renderView(array $options): string } /** - * @phpstan-return \Closure(int $page): string + * @return \Closure(int $page): string */ protected function createRouteGenerator(): \Closure { @@ -73,7 +73,7 @@ protected function createRouteGenerator(): \Closure protected function assertRenderedView(string $expected, string $result): void { - self::assertSame($this->filterExpectedView($expected), $result); + $this->assertSame($this->filterExpectedView($expected), $result); } protected function filterExpectedView(string $expected): string diff --git a/lib/Core/View/Template/DefaultTemplate.php b/lib/Core/View/Template/DefaultTemplate.php index a71c92fd..6a96f9ac 100644 --- a/lib/Core/View/Template/DefaultTemplate.php +++ b/lib/Core/View/Template/DefaultTemplate.php @@ -148,6 +148,6 @@ public function separator(): string private function generateSpan(string $class, int|string $page): string { - return str_replace(['%class%', '%text%'], [$class, $page], $this->option('span_template')); + return str_replace(['%class%', '%text%'], [$class, (string) $page], $this->option('span_template')); } } diff --git a/lib/Core/View/Template/Template.php b/lib/Core/View/Template/Template.php index b16ebe80..f262f96a 100644 --- a/lib/Core/View/Template/Template.php +++ b/lib/Core/View/Template/Template.php @@ -14,9 +14,7 @@ abstract class Template implements TemplateInterface private array $options; /** - * @var callable|RouteGeneratorInterface|null - * - * @phpstan-var callable(int $page): string|RouteGeneratorInterface|null + * @var (callable(int $page): string)|RouteGeneratorInterface|null */ private $routeGenerator; @@ -66,7 +64,7 @@ protected function getDefaultOptions(): array } /** - * @phpstan-return callable(int $page): string|RouteGeneratorInterface + * @return (callable(int $page): string)|RouteGeneratorInterface * * @throws RuntimeException if the route generator has not been set */ diff --git a/lib/Core/View/TemplateView.php b/lib/Core/View/TemplateView.php index 4d3b5dcf..8a1b7533 100644 --- a/lib/Core/View/TemplateView.php +++ b/lib/Core/View/TemplateView.php @@ -35,9 +35,8 @@ public function render(PagerfantaInterface $pagerfanta, callable $routeGenerator } /** - * @param array $options - * - * @phpstan-param callable(int $page): string|RouteGeneratorInterface $routeGenerator + * @param callable(int $page): string|RouteGeneratorInterface $routeGenerator + * @param array $options */ private function configureTemplate(callable|RouteGeneratorInterface $routeGenerator, array $options): void { diff --git a/lib/Core/View/View.php b/lib/Core/View/View.php index e74969b5..196da010 100644 --- a/lib/Core/View/View.php +++ b/lib/Core/View/View.php @@ -12,23 +12,23 @@ abstract class View implements ViewInterface protected PagerfantaInterface $pagerfanta; /** - * @phpstan-var positive-int|null + * @var positive-int|null */ protected ?int $currentPage = null; /** - * @phpstan-var positive-int|null + * @var positive-int|null */ protected ?int $nbPages = null; protected ?int $proximity = null; /** - * @phpstan-var positive-int|null + * @var positive-int|null */ protected ?int $startPage = null; /** - * @phpstan-var positive-int|null + * @var positive-int|null */ protected ?int $endPage = null; diff --git a/lib/Twig/Tests/Extension/PagerfantaRuntimeTest.php b/lib/Twig/Tests/Extension/PagerfantaRuntimeTest.php index fdcc0009..9b88a49f 100644 --- a/lib/Twig/Tests/Extension/PagerfantaRuntimeTest.php +++ b/lib/Twig/Tests/Extension/PagerfantaRuntimeTest.php @@ -14,23 +14,19 @@ final class PagerfantaRuntimeTest extends TestCase { - private ViewFactory $viewFactory; - - private RouteGeneratorFactoryInterface $routeGeneratorFactory; - private PagerfantaRuntime $extension; protected function setUp(): void { - $this->viewFactory = new ViewFactory(); - $this->viewFactory->set('default', new DefaultView()); + $viewFactory = new ViewFactory(); + $viewFactory->set('default', new DefaultView()); - $this->routeGeneratorFactory = $this->createRouteGeneratorFactory(); + $routeGeneratorFactory = $this->createRouteGeneratorFactory(); $this->extension = new PagerfantaRuntime( 'default', - $this->viewFactory, - $this->routeGeneratorFactory + $viewFactory, + $routeGeneratorFactory ); } @@ -66,9 +62,7 @@ public function __invoke(int $page): string } /** - * @return Pagerfanta - * - * @phpstan-return Pagerfanta> + * @return Pagerfanta> */ private function createPagerfanta(): Pagerfanta { @@ -141,7 +135,7 @@ public function testTheDefaultPagerfantaViewIsRenderedWhenConvertingTheViewNameF public function testAPageUrlCanBeGenerated(): void { - self::assertSame('/my-page?page=1', $this->extension->getPageUrl($this->createPagerfanta(), 1)); + $this->assertSame('/my-page?page=1', $this->extension->getPageUrl($this->createPagerfanta(), 1)); } public function testAPageUrlCannotBeGeneratedIfThePageIsOutOfBounds(): void @@ -154,7 +148,7 @@ public function testAPageUrlCannotBeGeneratedIfThePageIsOutOfBounds(): void private function assertViewOutputMatches(string $view, string $expected): void { - self::assertSame($this->removeWhitespacesBetweenTags($expected), $view); + $this->assertSame($this->removeWhitespacesBetweenTags($expected), $view); } private function removeWhitespacesBetweenTags(string $string): string diff --git a/lib/Twig/Tests/View/TwigViewIntegrationTest.php b/lib/Twig/Tests/View/TwigViewIntegrationTest.php index cab9e380..4924fbc9 100644 --- a/lib/Twig/Tests/View/TwigViewIntegrationTest.php +++ b/lib/Twig/Tests/View/TwigViewIntegrationTest.php @@ -41,15 +41,16 @@ protected function setUp(): void } /** - * @return Pagerfanta - * - * @phpstan-return Pagerfanta> + * @return Pagerfanta> */ private function createPagerfanta(): Pagerfanta { return new Pagerfanta(new FixedAdapter(100, range(1, 100))); } + /** + * @return \Generator, 2: non-empty-string}> + */ public static function dataPagerfantaRenderer(): \Generator { yield 'default template at page 1' => [ @@ -372,25 +373,25 @@ public static function dataPagerfantaRenderer(): \Generator } /** + * @param positive-int $page * @param array $options - * - * @phpstan-param positive-int $page + * @param non-empty-string $expectedOutput */ #[DataProvider('dataPagerfantaRenderer')] - public function testPagerfantaRendering(int $page, array $options, string $testOutput): void + public function testPagerfantaRendering(int $page, array $options, string $expectedOutput): void { $pagerfanta = $this->createPagerfanta(); $pagerfanta->setCurrentPage($page); $this->assertViewOutputMatches( $this->twig->render('integration.html.twig', ['pager' => $pagerfanta, 'options' => $options]), - $testOutput + $expectedOutput ); } public function testPagerfantaRenderingWithEmptyOptions(): void { - self::assertNotEmpty((new TwigView($this->twig))->render( + $this->assertNotEmpty((new TwigView($this->twig))->render( $this->createPagerfanta(), $this->createRouteGeneratorFactory()->create() )); @@ -461,7 +462,7 @@ public function load($class) private function assertViewOutputMatches(string $view, string $expected): void { - self::assertSame($this->removeWhitespacesBetweenTags($expected), $view); + $this->assertSame($this->removeWhitespacesBetweenTags($expected), $view); } private function removeWhitespacesBetweenTags(string $string): string diff --git a/lib/Twig/Tests/View/TwigViewTest.php b/lib/Twig/Tests/View/TwigViewTest.php index 26583205..8fac0357 100644 --- a/lib/Twig/Tests/View/TwigViewTest.php +++ b/lib/Twig/Tests/View/TwigViewTest.php @@ -28,12 +28,13 @@ public function testRendersWithATemplateSpecifiedInTheOptions(): void $template = $this->createMock(Template::class); // As of Twig 3.9, the internal wrapper implementation changed to accommodate the new yield strategy + /** @phpstan-ignore-next-line function.alreadyNarrowedType */ if (method_exists(Template::class, 'yieldBlock')) { - $template->expects(self::once()) + $template->expects($this->once()) ->method('renderBlock') ->willReturn('Twig template'); } else { - $template->expects(self::once()) + $template->expects($this->once()) ->method('displayBlock') ->willReturnCallback( static function (): void { @@ -42,19 +43,20 @@ static function (): void { ); } - $this->twig->expects(self::once()) + $this->twig->expects($this->once()) ->method('load') ->with($options['template']) ->willReturn(new TemplateWrapper($this->twig, $template)); // As of Twig 3.14, mergeGlobals is deprecated and not called when rendering + /** @phpstan-ignore-next-line function.alreadyNarrowedType */ if (!method_exists(Environment::class, 'resetGlobals')) { - $this->twig->expects(self::once()) + $this->twig->expects($this->once()) ->method('mergeGlobals') ->willReturn([]); } - self::assertSame('Twig template', (new TwigView($this->twig, 'constructor.html.twig'))->render( + $this->assertSame('Twig template', (new TwigView($this->twig, 'constructor.html.twig'))->render( $this->createPagerfanta(), $this->createRouteGenerator(), $options @@ -67,12 +69,13 @@ public function testRendersWithATemplateSpecifiedInTheConstructorWhenNotSetInThe $template = $this->createMock(Template::class); // As of Twig 3.9, the internal wrapper implementation changed to accommodate the new yield strategy + /** @phpstan-ignore-next-line function.alreadyNarrowedType */ if (method_exists(Template::class, 'yieldBlock')) { - $template->expects(self::once()) + $template->expects($this->once()) ->method('renderBlock') ->willReturn('Twig template'); } else { - $template->expects(self::once()) + $template->expects($this->once()) ->method('displayBlock') ->willReturnCallback( static function (): void { @@ -81,19 +84,20 @@ static function (): void { ); } - $this->twig->expects(self::once()) + $this->twig->expects($this->once()) ->method('load') ->with('constructor.html.twig') ->willReturn(new TemplateWrapper($this->twig, $template)); // As of Twig 3.14, mergeGlobals is deprecated and not called when rendering + /** @phpstan-ignore-next-line function.alreadyNarrowedType */ if (!method_exists(Environment::class, 'resetGlobals')) { - $this->twig->expects(self::once()) + $this->twig->expects($this->once()) ->method('mergeGlobals') ->willReturn([]); } - self::assertSame('Twig template', (new TwigView($this->twig, 'constructor.html.twig'))->render( + $this->assertSame('Twig template', (new TwigView($this->twig, 'constructor.html.twig'))->render( $this->createPagerfanta(), $this->createRouteGenerator() )); @@ -105,12 +109,13 @@ public function testRendersWithTheDefaultTemplateWhenNotSetInConstructorOrOption $template = $this->createMock(Template::class); // As of Twig 3.9, the internal wrapper implementation changed to accommodate the new yield strategy + /** @phpstan-ignore-next-line function.alreadyNarrowedType */ if (method_exists(Template::class, 'yieldBlock')) { - $template->expects(self::once()) + $template->expects($this->once()) ->method('renderBlock') ->willReturn('Twig template'); } else { - $template->expects(self::once()) + $template->expects($this->once()) ->method('displayBlock') ->willReturnCallback( static function (): void { @@ -119,25 +124,24 @@ static function (): void { ); } - $this->twig->expects(self::once()) + $this->twig->expects($this->once()) ->method('load') ->with(TwigView::DEFAULT_TEMPLATE) ->willReturn(new TemplateWrapper($this->twig, $template)); // As of Twig 3.14, mergeGlobals is deprecated and not called when rendering + /** @phpstan-ignore-next-line function.alreadyNarrowedType */ if (!method_exists(Environment::class, 'resetGlobals')) { - $this->twig->expects(self::once()) + $this->twig->expects($this->once()) ->method('mergeGlobals') ->willReturn([]); } - self::assertSame('Twig template', (new TwigView($this->twig))->render($this->createPagerfanta(), $this->createRouteGenerator())); + $this->assertSame('Twig template', (new TwigView($this->twig))->render($this->createPagerfanta(), $this->createRouteGenerator())); } /** - * @return Pagerfanta - * - * @phpstan-return Pagerfanta> + * @return Pagerfanta> */ private function createPagerfanta(): Pagerfanta { diff --git a/lib/Twig/View/TwigView.php b/lib/Twig/View/TwigView.php index 5568cee3..06d11edc 100644 --- a/lib/Twig/View/TwigView.php +++ b/lib/Twig/View/TwigView.php @@ -53,7 +53,7 @@ public function render(PagerfantaInterface $pagerfanta, callable $routeGenerator } /** - * @phpstan-param callable(int $page): string|RouteGeneratorInterface $routeGenerator + * @param (callable(int $page): string)|RouteGeneratorInterface $routeGenerator */ private function decorateRouteGenerator(callable|RouteGeneratorInterface $routeGenerator): RouteGeneratorDecorator { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2fc7e56d..9f6d51d0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,137 +1,122 @@ parameters: ignoreErrors: - - message: "#^Method Pagerfanta\\\\Doctrine\\\\Collections\\\\CollectionAdapter\\:\\:getNbResults\\(\\) should return int\\<0, max\\> but returns int\\.$#" - count: 1 - path: lib/Adapter/Doctrine/Collections/CollectionAdapter.php - - - - message: "#^Method Pagerfanta\\\\Doctrine\\\\Collections\\\\SelectableAdapter\\:\\:getNbResults\\(\\) should return int\\<0, max\\> but returns int\\.$#" - count: 1 - path: lib/Adapter/Doctrine/Collections/SelectableAdapter.php - - - - message: "#^Parameter \\#1 \\$array of function array_values expects array\\, iterable\\<\\(int\\|string\\), int\\> given\\.$#" - count: 1 - path: lib/Adapter/Doctrine/Collections/Tests/CollectionAdapterTest.php - - - - message: "#^Method Pagerfanta\\\\Doctrine\\\\DBAL\\\\QueryAdapter\\:\\:getNbResults\\(\\) should return int\\<0, max\\> but returns int\\.$#" + message: '#^Method Pagerfanta\\Doctrine\\DBAL\\QueryAdapter\:\:getNbResults\(\) should return int\<0, max\> but returns int\.$#' + identifier: return.type count: 1 path: lib/Adapter/Doctrine/DBAL/QueryAdapter.php - - message: "#^Method Pagerfanta\\\\Doctrine\\\\DBAL\\\\QueryAdapter\\:\\:getSlice\\(\\) should return iterable\\<\\(int\\|string\\), T\\> but returns array\\\\>\\.$#" + message: '#^Method Pagerfanta\\Doctrine\\DBAL\\QueryAdapter\:\:getSlice\(\) should return iterable\<\(int\|string\), T\> but returns list\\>\.$#' + identifier: return.type count: 1 path: lib/Adapter/Doctrine/DBAL/QueryAdapter.php - - message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Query\\\\QueryBuilder\\:\\:resetQueryPart\\(\\)\\.$#" + message: '#^Call to an undefined method Doctrine\\DBAL\\Query\\QueryBuilder\:\:resetQueryPart\(\)\.$#' + identifier: method.notFound count: 1 path: lib/Adapter/Doctrine/DBAL/SingleTableQueryAdapter.php - - message: "#^Method Pagerfanta\\\\Doctrine\\\\MongoDBODM\\\\QueryAdapter\\:\\:getNbResults\\(\\) should return int\\<0, max\\> but returns array\\\\|int\\|object\\|null\\.$#" + message: '#^Method Pagerfanta\\Doctrine\\MongoDBODM\\QueryAdapter\:\:getNbResults\(\) should return int\<0, max\> but returns array\\|int\|object\|null\.$#' + identifier: return.type count: 1 path: lib/Adapter/Doctrine/MongoDBODM/QueryAdapter.php - - message: "#^Method Pagerfanta\\\\Doctrine\\\\MongoDBODM\\\\QueryAdapter\\:\\:getSlice\\(\\) should return iterable\\<\\(int\\|string\\), T\\> but returns array\\\\|int\\|object\\|null\\.$#" + message: '#^Method Pagerfanta\\Doctrine\\MongoDBODM\\QueryAdapter\:\:getSlice\(\) should return iterable\<\(int\|string\), T\> but returns array\\|int\|object\|null\.$#' + identifier: return.type count: 1 path: lib/Adapter/Doctrine/MongoDBODM/QueryAdapter.php - - message: "#^PHPDoc tag @var for variable \\$aggregation contains unresolvable type\\.$#" + message: '#^PHPDoc tag @var for variable \$aggregation contains unresolvable type\.$#' + identifier: varTag.unresolvableType count: 2 path: lib/Adapter/Doctrine/MongoDBODM/Tests/AggregationAdapterTest.php - - message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#" + message: '#^Return type of call to method PHPUnit\\Framework\\TestCase\:\:createMock\(\) contains unresolvable type\.$#' + identifier: method.unresolvableReturnType count: 2 path: lib/Adapter/Doctrine/MongoDBODM/Tests/AggregationAdapterTest.php - - message: "#^PHPDoc tag @var for variable \\$query contains unresolvable type\\.$#" + message: '#^PHPDoc tag @var for variable \$query contains unresolvable type\.$#' + identifier: varTag.unresolvableType count: 2 path: lib/Adapter/Doctrine/MongoDBODM/Tests/QueryAdapterTest.php - - message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#" + message: '#^Return type of call to method PHPUnit\\Framework\\TestCase\:\:createMock\(\) contains unresolvable type\.$#' + identifier: method.unresolvableReturnType count: 2 path: lib/Adapter/Doctrine/MongoDBODM/Tests/QueryAdapterTest.php - - message: "#^Cannot access offset 0 on Traversable\\<\\(int\\|string\\), mixed\\>\\.$#" + message: '#^Cannot access offset 0 on Traversable\<\(int\|string\), mixed\>\.$#' + identifier: offsetAccess.nonOffsetAccessible count: 3 path: lib/Adapter/Doctrine/ORM/Tests/QueryAdapterTest.php - - message: "#^Call to an undefined method Doctrine\\\\Common\\\\Collections\\\\Collection\\|PHPCR\\\\Query\\\\QueryResultInterface\\:\\:getRows\\(\\)\\.$#" + message: '#^Call to an undefined method Doctrine\\Common\\Collections\\Collection\|PHPCR\\Query\\QueryResultInterface\:\:getRows\(\)\.$#' + identifier: method.notFound count: 1 path: lib/Adapter/Doctrine/PHPCRODM/QueryAdapter.php - - message: "#^Call to an undefined method Iterator\\\\:\\:count\\(\\)\\.$#" + message: '#^Call to an undefined method Iterator\\:\:count\(\)\.$#' + identifier: method.notFound count: 1 path: lib/Adapter/Doctrine/PHPCRODM/QueryAdapter.php - - message: "#^Method Pagerfanta\\\\Elastica\\\\ElasticaAdapter\\:\\:getNbResults\\(\\) should return int\\<0, max\\> but returns int\\.$#" + message: '#^Method Pagerfanta\\Elastica\\ElasticaAdapter\:\:getNbResults\(\) should return int\<0, max\> but returns int\.$#' + identifier: return.type count: 2 path: lib/Adapter/Elastica/ElasticaAdapter.php - - message: "#^Method Pagerfanta\\\\Elastica\\\\ElasticaAdapter\\:\\:getSlice\\(\\) should return iterable\\<\\(int\\|string\\), T\\> but returns Elastica\\\\ResultSet\\.$#" + message: '#^Method Pagerfanta\\Elastica\\ElasticaAdapter\:\:getSlice\(\) should return iterable\<\(int\|string\), T\> but returns Elastica\\ResultSet\.$#' + identifier: return.type count: 1 path: lib/Adapter/Elastica/ElasticaAdapter.php - - message: "#^Method Pagerfanta\\\\Solarium\\\\SolariumAdapter\\:\\:getNbResults\\(\\) should return int\\<0, max\\> but returns int\\|null\\.$#" + message: '#^Method Pagerfanta\\Solarium\\SolariumAdapter\:\:getNbResults\(\) should return int\<0, max\> but returns int\|null\.$#' + identifier: return.type count: 1 path: lib/Adapter/Solarium/SolariumAdapter.php - - message: "#^Parameter \\#2 \\$length of method Pagerfanta\\\\Adapter\\\\AdapterInterface\\\\:\\:getSlice\\(\\) expects int\\<0, max\\>, int given\\.$#" + message: '#^Parameter \#2 \$length of method Pagerfanta\\Adapter\\AdapterInterface\\:\:getSlice\(\) expects int\<0, max\>, int given\.$#' + identifier: argument.type count: 1 path: lib/Core/Adapter/ConcatenationAdapter.php - - message: "#^Method Pagerfanta\\\\Pagerfanta\\:\\:calculateNbPages\\(\\) should return int\\<0, max\\> but returns int\\.$#" + message: '#^Property Pagerfanta\\Adapter\\ConcatenationAdapter\\:\:\$adaptersNbResultsCache \(list\\>\|null\) does not accept non\-empty\-array\, int\<0, max\>\>\.$#' + identifier: assign.propertyType count: 1 - path: lib/Core/Pagerfanta.php + path: lib/Core/Adapter/ConcatenationAdapter.php - - message: "#^Method Pagerfanta\\\\Pagerfanta\\:\\:getPageNumberForItemAtPosition\\(\\) should return int\\<1, max\\> but returns int\\.$#" + message: '#^Method Pagerfanta\\Pagerfanta\:\:calculateNbPages\(\) should return int\<0, max\> but returns int\.$#' + identifier: return.type count: 1 path: lib/Core/Pagerfanta.php - - message: "#^Property Pagerfanta\\\\Tests\\\\Adapter\\\\ArrayAdapterTest\\:\\:\\$adapter \\(Pagerfanta\\\\Adapter\\\\ArrayAdapter\\\\>\\) does not accept Pagerfanta\\\\Adapter\\\\ArrayAdapter\\\\.$#" + message: '#^Method Pagerfanta\\Pagerfanta\:\:getPageNumberForItemAtPosition\(\) should return int\<1, max\> but returns int\.$#' + identifier: return.type count: 1 - path: lib/Core/Tests/Adapter/ArrayAdapterTest.php - - - - message: "#^Property Pagerfanta\\\\Tests\\\\Adapter\\\\TransformingAdapterTest\\:\\:\\$adapter \\(Pagerfanta\\\\Adapter\\\\TransformingAdapter\\, string\\>\\) does not accept Pagerfanta\\\\Adapter\\\\TransformingAdapter\\\\.$#" - count: 2 - path: lib/Core/Tests/Adapter/TransformingAdapterTest.php + path: lib/Core/Pagerfanta.php - - message: "#^Method Pagerfanta\\\\View\\\\View\\:\\:calculateEndPageForStartPageUnderflow\\(\\) should return int\\<1, max\\> but returns int\\.$#" + message: '#^Method Pagerfanta\\View\\View\:\:calculateEndPageForStartPageUnderflow\(\) should return int\<1, max\> but returns int\.$#' + identifier: return.type count: 1 path: lib/Core/View/View.php - - - message: "#^Method Pagerfanta\\\\Twig\\\\Tests\\\\Extension\\\\PagerfantaRuntimeTest\\:\\:createPagerfanta\\(\\) should return Pagerfanta\\\\Pagerfanta\\\\> but returns Pagerfanta\\\\Pagerfanta\\\\.$#" - count: 1 - path: lib/Twig/Tests/Extension/PagerfantaRuntimeTest.php - - - - message: "#^Method Pagerfanta\\\\Twig\\\\Tests\\\\View\\\\TwigViewIntegrationTest\\:\\:createPagerfanta\\(\\) should return Pagerfanta\\\\Pagerfanta\\\\> but returns Pagerfanta\\\\Pagerfanta\\\\.$#" - count: 1 - path: lib/Twig/Tests/View/TwigViewIntegrationTest.php - - - - message: "#^Method Pagerfanta\\\\Twig\\\\Tests\\\\View\\\\TwigViewTest\\:\\:createPagerfanta\\(\\) should return Pagerfanta\\\\Pagerfanta\\\\> but returns Pagerfanta\\\\Pagerfanta\\\\.$#" - count: 1 - path: lib/Twig/Tests/View/TwigViewTest.php -