diff --git a/.gitattributes b/.gitattributes index 8e7a0236..86cfe4c3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ /.git* export-ignore /.php-cs-fixer.* export-ignore /*.md export-ignore -/phpstan.* export-ignore +/phpstan* export-ignore /phpunit.xml.dist export-ignore /docs export-ignore /tests export-ignore diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6d95c99f..5f150ab0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,7 +1,32 @@ parameters: ignoreErrors: - - message: "#^Instanceof between Doctrine\\\\ORM\\\\Query\\\\AST\\\\ConditionalExpression and Doctrine\\\\ORM\\\\Query\\\\AST\\\\ConditionalPrimary will always evaluate to false\\.$#" + message: "#^Method Knp\\\\Component\\\\Pager\\\\Event\\\\Subscriber\\\\Sortable\\\\ArraySubscriber\\:\\:sortFunction\\(\\) has parameter \\$object1 with no value type specified in iterable type array\\.$#" count: 1 - path: src/Knp/Component/Pager/Event/Subscriber/Filtration/Doctrine/ORM/Query/WhereWalker.php + path: src/Knp/Component/Pager/Event/Subscriber/Sortable/ArraySubscriber.php + + - + message: "#^Method Knp\\\\Component\\\\Pager\\\\Event\\\\Subscriber\\\\Sortable\\\\ArraySubscriber\\:\\:sortFunction\\(\\) has parameter \\$object2 with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Knp/Component/Pager/Event/Subscriber/Sortable/ArraySubscriber.php + + - + message: "#^Class Knp\\\\Component\\\\Pager\\\\Pagination\\\\AbstractPagination implements generic interface Iterator but does not specify its types\\: TKey, TValue$#" + count: 1 + path: src/Knp/Component/Pager/Pagination/AbstractPagination.php + + - + message: "#^PHPDoc tag @var for property Knp\\\\Component\\\\Pager\\\\Pagination\\\\AbstractPagination\\:\\:\\$items with type iterable\\\\|object is not subtype of native type iterable\\.$#" + count: 1 + path: src/Knp/Component/Pager/Pagination/AbstractPagination.php + + - + message: "#^Property Knp\\\\Component\\\\Pager\\\\Pagination\\\\AbstractPagination\\:\\:\\$items type has no value type specified in iterable type iterable\\.$#" + count: 1 + path: src/Knp/Component/Pager/Pagination/AbstractPagination.php + + - + message: "#^Interface Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface extends generic interface ArrayAccess but does not specify its types\\: TKey, TValue$#" + count: 1 + path: src/Knp/Component/Pager/Pagination/PaginationInterface.php diff --git a/phpstan.neon b/phpstan.neon index 3f2c8766..13f77f7c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 5 + level: 6 paths: - src includes: diff --git a/src/Knp/Component/Pager/Event/AfterEvent.php b/src/Knp/Component/Pager/Event/AfterEvent.php index 56a68fec..84a32e09 100644 --- a/src/Knp/Component/Pager/Event/AfterEvent.php +++ b/src/Knp/Component/Pager/Event/AfterEvent.php @@ -10,13 +10,20 @@ */ final class AfterEvent extends Event { + /** @var PaginationInterface */ private PaginationInterface $pagination; + /** + * @param PaginationInterface $paginationView + */ public function __construct(PaginationInterface $paginationView) { $this->pagination = $paginationView; } + /** + * @return PaginationInterface + */ public function getPaginationView(): PaginationInterface { return $this->pagination; diff --git a/src/Knp/Component/Pager/Event/ItemsEvent.php b/src/Knp/Component/Pager/Event/ItemsEvent.php index 2411e048..c99af7bc 100644 --- a/src/Knp/Component/Pager/Event/ItemsEvent.php +++ b/src/Knp/Component/Pager/Event/ItemsEvent.php @@ -15,7 +15,7 @@ final class ItemsEvent extends Event public mixed $target = null; /** - * List of options + * @var array */ public array $options; @@ -31,6 +31,10 @@ final class ItemsEvent extends Event private int $offset; private int $limit; + + /** + * @var array + */ private array $customPaginationParams = []; public function __construct(int $offset, int $limit) @@ -44,6 +48,9 @@ public function setCustomPaginationParameter(string $name, mixed $value): void $this->customPaginationParams[$name] = $value; } + /** + * @return array + */ public function getCustomPaginationParameters(): array { return $this->customPaginationParams; diff --git a/src/Knp/Component/Pager/Event/PaginationEvent.php b/src/Knp/Component/Pager/Event/PaginationEvent.php index 50f6f956..b3b9aad8 100644 --- a/src/Knp/Component/Pager/Event/PaginationEvent.php +++ b/src/Knp/Component/Pager/Event/PaginationEvent.php @@ -16,17 +16,26 @@ final class PaginationEvent extends Event public mixed $target = null; /** - * List of options + * @var array */ public array $options; + /** + * @var PaginationInterface + */ private PaginationInterface $pagination; + /** + * @param PaginationInterface $pagination + */ public function setPagination(PaginationInterface $pagination): void { $this->pagination = $pagination; } + /** + * @return PaginationInterface + */ public function getPagination(): PaginationInterface { return $this->pagination; diff --git a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Callback/CallbackPagination.php b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Callback/CallbackPagination.php index 1734fdd2..8b590f4f 100644 --- a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Callback/CallbackPagination.php +++ b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Callback/CallbackPagination.php @@ -30,6 +30,9 @@ public function getPaginationCount(): int return call_user_func($this->count); } + /** + * @return array + */ public function getPaginationItems(int $offset, int $limit): array { return call_user_func($this->items, $offset, $limit); diff --git a/src/Knp/Component/Pager/Event/Subscriber/Sortable/ArraySubscriber.php b/src/Knp/Component/Pager/Event/Subscriber/Sortable/ArraySubscriber.php index 72afa098..36ba4fe3 100644 --- a/src/Knp/Component/Pager/Event/Subscriber/Sortable/ArraySubscriber.php +++ b/src/Knp/Component/Pager/Event/Subscriber/Sortable/ArraySubscriber.php @@ -70,6 +70,9 @@ public function items(ItemsEvent $event): void ]); } + /** + * @param array $options + */ private function getSortDirection(array $options): string { if (!$this->argumentAccess->has($options[PaginatorInterface::SORT_DIRECTION_PARAMETER_NAME])) { @@ -83,7 +86,7 @@ private function getSortDirection(array $options): string return 'desc'; } - private function proxySortFunction(&$target, $sortField, $sortDirection): bool + private function proxySortFunction(mixed &$target, string $sortField, string $sortDirection): bool { $this->currentSortingField = $sortField; $this->sortDirection = $sortDirection; diff --git a/src/Knp/Component/Pager/Event/Subscriber/Sortable/SolariumQuerySubscriber.php b/src/Knp/Component/Pager/Event/Subscriber/Sortable/SolariumQuerySubscriber.php index e461eb78..f1aa67a8 100644 --- a/src/Knp/Component/Pager/Event/Subscriber/Sortable/SolariumQuerySubscriber.php +++ b/src/Knp/Component/Pager/Event/Subscriber/Sortable/SolariumQuerySubscriber.php @@ -56,7 +56,7 @@ public static function getSubscribedEvents(): array ]; } - private function getSortDirection($event): string + private function getSortDirection(ItemsEvent $event): string { $sortDir = $event->options[PaginatorInterface::SORT_DIRECTION_PARAMETER_NAME]; diff --git a/src/Knp/Component/Pager/Pagination/AbstractPagination.php b/src/Knp/Component/Pager/Pagination/AbstractPagination.php index c711ce0a..55eac10e 100644 --- a/src/Knp/Component/Pager/Pagination/AbstractPagination.php +++ b/src/Knp/Component/Pager/Pagination/AbstractPagination.php @@ -14,9 +14,12 @@ abstract class AbstractPagination implements Iterator, PaginationInterface { protected ?int $currentPageNumber = null; protected ?int $numItemsPerPage = null; + /** @var iterable|object */ protected iterable $items = []; protected ?int $totalCount = null; + /** @var array */ protected ?array $paginatorOptions = null; + /** @var array */ protected ?array $customParameters = null; public function rewind(): void diff --git a/src/Knp/Component/Pager/Pagination/PaginationInterface.php b/src/Knp/Component/Pager/Pagination/PaginationInterface.php index 65cadf0f..987d90bc 100644 --- a/src/Knp/Component/Pager/Pagination/PaginationInterface.php +++ b/src/Knp/Component/Pager/Pagination/PaginationInterface.php @@ -50,7 +50,7 @@ public function setItems(iterable $items): void; public function getItems(): iterable; /** - * @param array $options + * @param array $options */ public function setPaginatorOptions(array $options): void; @@ -60,7 +60,7 @@ public function setPaginatorOptions(array $options): void; public function getPaginatorOption(string $name): mixed; /** - * @param array $parameters + * @param array $parameters */ public function setCustomParameters(array $parameters): void; diff --git a/src/Knp/Component/Pager/Pagination/SlidingPagination.php b/src/Knp/Component/Pager/Pagination/SlidingPagination.php index 23f7d8bb..dc762c29 100644 --- a/src/Knp/Component/Pager/Pagination/SlidingPagination.php +++ b/src/Knp/Component/Pager/Pagination/SlidingPagination.php @@ -14,7 +14,7 @@ * * @template-extends AbstractPagination */ -final class SlidingPagination extends AbstractPagination +final class SlidingPagination extends AbstractPagination implements \Stringable { /** * Pagination page range @@ -45,6 +45,9 @@ public function __toString(): string return $output; } + /** + * @return array + */ public function getPaginationData(): array { $pageCount = (int) ceil($this->totalCount / $this->numItemsPerPage); diff --git a/src/Knp/Component/Pager/Paginator.php b/src/Knp/Component/Pager/Paginator.php index d4457c87..5ebc3ce0 100644 --- a/src/Knp/Component/Pager/Paginator.php +++ b/src/Knp/Component/Pager/Paginator.php @@ -44,21 +44,27 @@ public function __construct(EventDispatcherInterface $eventDispatcher, ArgumentA } /** - * Override the default paginator options - * to be reused for paginations + * Override the default paginator options to be reused for paginations + * + * @param array $options */ public function setDefaultPaginatorOptions(array $options): void { $this->defaultOptions = \array_merge($this->defaultOptions, $options); } + /** + * @param array $options + * + * @return PaginationInterface + */ public function paginate($target, int $page = 1, int $limit = null, array $options = []): PaginationInterface { if ($page <= 0) { throw PageNumberInvalidException::create($page); } - $limit = $limit ?? $this->defaultOptions[self::DEFAULT_LIMIT]; + $limit = $limit ?? (int) $this->defaultOptions[self::DEFAULT_LIMIT]; if ($limit <= 0) { throw PageLimitInvalidException::create($limit); } diff --git a/src/Knp/Component/Pager/PaginatorInterface.php b/src/Knp/Component/Pager/PaginatorInterface.php index 96b6ddf9..3efec7c7 100644 --- a/src/Knp/Component/Pager/PaginatorInterface.php +++ b/src/Knp/Component/Pager/PaginatorInterface.php @@ -35,13 +35,15 @@ interface PaginatorInterface * pagination object (might be aggregated helper object) * responsible for the pagination result representation * - * @param mixed $target anything what needs to be paginated - * @param int $page page number, starting from 1 - * @param int|null $limit number of items per page - * @param array $options less used options: - * bool $distinct default true for distinction of results - * string $alias pagination alias, default none - * array $sortFieldAllowList sortable allow list for target fields being paginated + * @param mixed $target anything what needs to be paginated + * @param int $page page number, starting from 1 + * @param int|null $limit number of items per page + * @param array $options less used options: + * bool $distinct default true for distinction of results + * string $alias pagination alias, default none + * array $sortFieldAllowList sortable allow list for target fields being paginated + * + * @return PaginationInterface */ public function paginate(mixed $target, int $page = 1, int $limit = null, array $options = []): PaginationInterface; } diff --git a/tests/Test/Fixture/Document/Image.php b/tests/Test/Fixture/Document/Image.php index c3828062..5e6eec6b 100644 --- a/tests/Test/Fixture/Document/Image.php +++ b/tests/Test/Fixture/Document/Image.php @@ -26,20 +26,14 @@ final class Image private $file; /** - * Set file. - * * @param int|string $file */ - public function setFile($file): self + public function setFile($file): void { $this->file = $file; - - return $this; } /** - * Get file. - * * @return int|string */ public function getFile()