diff options
| author | 2023-04-17 08:30:21 +0200 | |
|---|---|---|
| committer | 2023-04-17 08:30:21 +0200 | |
| commit | f3760f138dcbaf7a2190336a0378cf1b2190c9f5 (patch) | |
| tree | 6fac8fbf9efd7aa74a8e3970ab70ccf85287b2cd /lib/Minz/Paginator.php | |
| parent | 41fa4e746df8c2e2399ed753b4994ca85cb21358 (diff) | |
Complete PHPStan Level 6 (#5305)
* Complete PHPStan Level 6
Fix https://github.com/FreshRSS/FreshRSS/issues/4112
And initiate PHPStan Level 7
* PHPStan Level 6 for tests
* Use phpstan/phpstan-phpunit
* Update to PHPStan version 1.10
* Fix mixed bug
* Fix mixed return bug
* Fix paginator bug
* Fix FreshRSS_UserConfiguration
* A couple more Minz_Configuration bug fixes
* A few trivial PHPStan Level 7 fixes
* A few more simple PHPStan Level 7
* More files passing PHPStan Level 7
Add interface to replace removed class from https://github.com/FreshRSS/FreshRSS/pull/5251
* A few more PHPStan Level 7 preparations
* A few last details
Diffstat (limited to 'lib/Minz/Paginator.php')
| -rw-r--r-- | lib/Minz/Paginator.php | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.php index e11dda11c..77bc3e5e0 100644 --- a/lib/Minz/Paginator.php +++ b/lib/Minz/Paginator.php @@ -37,11 +37,11 @@ class Minz_Paginator { * Constructeur * @param array<Minz_Model> $items les éléments à gérer */ - public function __construct ($items) { - $this->_items ($items); - $this->_nbItems (count ($this->items (true))); - $this->_nbItemsPerPage ($this->nbItemsPerPage); - $this->_currentPage ($this->currentPage); + public function __construct(array $items) { + $this->_items($items); + $this->_nbItems(count($this->items(true))); + $this->_nbItemsPerPage($this->nbItemsPerPage); + $this->_currentPage($this->currentPage); } /** @@ -49,25 +49,25 @@ class Minz_Paginator { * @param string $view nom du fichier de vue situé dans /app/views/helpers/ * @param int $getteur variable de type $_GET[] permettant de retrouver la page */ - public function render ($view, $getteur) { + public function render(string $view, int $getteur = 0): void { $view = APP_PATH . '/views/helpers/' . $view; - if (file_exists ($view)) { - include ($view); + if (file_exists($view)) { + include($view); } } /** * Permet de retrouver la page d'un élément donné * @param Minz_Model $item l'élément à retrouver - * @return float|false la page à laquelle se trouve l’élément, false si non trouvé + * @return int|false la page à laquelle se trouve l’élément, false si non trouvé */ - public function pageByItem ($item) { + public function pageByItem($item) { $i = 0; do { if ($item == $this->items[$i]) { - return ceil(($i + 1) / $this->nbItemsPerPage); + return (int)(ceil(($i + 1) / $this->nbItemsPerPage)); } $i++; } while ($i < $this->nbItems()); @@ -80,7 +80,7 @@ class Minz_Paginator { * @param Minz_Model $item the element to search * @return int|false the position of the element, or false if not found */ - public function positionByItem ($item) { + public function positionByItem($item) { $i = 0; do { @@ -96,9 +96,9 @@ class Minz_Paginator { /** * Permet de récupérer un item par sa position * @param int $pos la position de l'élément - * @return mixed item situé à $pos (dernier item si $pos<0, 1er si $pos>=count($items)) + * @return Minz_Model item situé à $pos (dernier item si $pos<0, 1er si $pos>=count($items)) */ - public function itemByPosition ($pos) { + public function itemByPosition(int $pos): Minz_Model { if ($pos < 0) { $pos = $this->nbItems () - 1; } @@ -116,7 +116,7 @@ class Minz_Paginator { * @param bool $all si à true, retourne tous les éléments sans prendre en compte la pagination * @return array<Minz_Model> */ - public function items ($all = false) { + public function items(bool $all = false): array { $array = array (); $nbItems = $this->nbItems (); @@ -141,30 +141,28 @@ class Minz_Paginator { return $array; } - public function nbItemsPerPage () { + public function nbItemsPerPage(): int { return $this->nbItemsPerPage; } - public function currentPage () { + public function currentPage(): int { return $this->currentPage; } - public function nbPage () { + public function nbPage(): int { return $this->nbPage; } - public function nbItems () { + public function nbItems(): int { return $this->nbItems; } /** * SETTEURS */ - public function _items ($items) { - if (is_array ($items)) { - $this->items = $items; - } - - $this->_nbPage (); + /** @param array<Minz_Model> $items */ + public function _items(?array $items): void { + $this->items = $items ?? []; + $this->_nbPage(); } - public function _nbItemsPerPage ($nbItemsPerPage) { + public function _nbItemsPerPage(int $nbItemsPerPage): void { if ($nbItemsPerPage > $this->nbItems ()) { $nbItemsPerPage = $this->nbItems (); } @@ -173,21 +171,21 @@ class Minz_Paginator { } $this->nbItemsPerPage = $nbItemsPerPage; - $this->_nbPage (); + $this->_nbPage(); } - public function _currentPage ($page) { + public function _currentPage(int $page): void { if ($page < 1 || ($page > $this->nbPage && $this->nbPage > 0)) { throw new Minz_CurrentPagePaginationException($page); } $this->currentPage = $page; } - private function _nbPage () { + private function _nbPage(): void { if ($this->nbItemsPerPage > 0) { $this->nbPage = (int)ceil($this->nbItems() / $this->nbItemsPerPage); } } - public function _nbItems ($value) { + public function _nbItems(int $value): void { $this->nbItems = $value; } } |
