| @@ -48,8 +48,8 @@ discard block | ||
| 48 | 48 | protected $pager; | 
| 49 | 49 | |
| 50 | 50 |      public function __construct(Pager $pager, $iteration = 1) { | 
| 51 | - $this->pager = $pager; | |
| 52 | - $this->iteration = (int) $iteration; | |
| 51 | + $this->pager = $pager; | |
| 52 | + $this->iteration = (int) $iteration; | |
| 53 | 53 | $this->populate(); | 
| 54 | 54 | } | 
| 55 | 55 | |
| @@ -73,7 +73,7 @@ discard block | ||
| 73 | 73 | */ | 
| 74 | 74 |      public function getOffset() { | 
| 75 | 75 | if (!$this->offset) | 
| 76 | - $this->offset = ($this->getIndex() * $this->getPager()->getResultsPerPage()); | |
| 76 | + $this->offset = ($this->getIndex() * $this->getPager()->getResultsPerPage()); | |
| 77 | 77 | return $this->offset; | 
| 78 | 78 | } | 
| 79 | 79 | |
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | */ | 
| 84 | 84 |      public function getResultCount() { | 
| 85 | 85 | if (!$this->resultCount) | 
| 86 | - $this->resultCount = $this->isLastPage() ? $this->getPager()->getTotalResultCount() - $this->getOffset() : $this->getPager()->getResultsPerPage(); | |
| 86 | + $this->resultCount = $this->isLastPage() ? $this->getPager()->getTotalResultCount() - $this->getOffset() : $this->getPager()->getResultsPerPage(); | |
| 87 | 87 | return $this->resultCount; | 
| 88 | 88 | } | 
| 89 | 89 | |
| @@ -93,7 +93,7 @@ discard block | ||
| 93 | 93 | */ | 
| 94 | 94 |      public function isFirstPage() { | 
| 95 | 95 | if (!$this->isFirstPage) | 
| 96 | - $this->isFirstPage = ($this->getIteration() == 1); | |
| 96 | + $this->isFirstPage = ($this->getIteration() == 1); | |
| 97 | 97 | return $this->isFirstPage; | 
| 98 | 98 | } | 
| 99 | 99 | |
| @@ -103,7 +103,7 @@ discard block | ||
| 103 | 103 | */ | 
| 104 | 104 |      public function isLastPage() { | 
| 105 | 105 | if (!$this->isLastPage) | 
| 106 | - $this->isLastPage = ($this->getIteration() == $this->pager->getNbPages()); | |
| 106 | + $this->isLastPage = ($this->getIteration() == $this->pager->getNbPages()); | |
| 107 | 107 | return $this->isLastPage; | 
| 108 | 108 | } | 
| 109 | 109 | |
| @@ -113,7 +113,7 @@ discard block | ||
| 113 | 113 | */ | 
| 114 | 114 |      public function isCurrentPage() { | 
| 115 | 115 | if (!$this->isCurrentPage) | 
| 116 | - $this->isCurrentPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration())); | |
| 116 | + $this->isCurrentPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration())); | |
| 117 | 117 | return $this->isCurrentPage; | 
| 118 | 118 | } | 
| 119 | 119 | |
| @@ -123,7 +123,7 @@ discard block | ||
| 123 | 123 | */ | 
| 124 | 124 |      public function isPreviousPage() { | 
| 125 | 125 | if (!$this->isPreviousPage) | 
| 126 | - $this->isPreviousPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration() - 1)); | |
| 126 | + $this->isPreviousPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration() - 1)); | |
| 127 | 127 | return $this->isPreviousPage; | 
| 128 | 128 | } | 
| 129 | 129 | |
| @@ -133,7 +133,7 @@ discard block | ||
| 133 | 133 | */ | 
| 134 | 134 |      public function isNextPage() { | 
| 135 | 135 | if (!$this->isNextPage) | 
| 136 | - $this->isNextPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration() + 1)); | |
| 136 | + $this->isNextPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration() + 1)); | |
| 137 | 137 | return $this->isNextPage; | 
| 138 | 138 | } | 
| 139 | 139 | |
| @@ -171,7 +171,7 @@ discard block | ||
| 171 | 171 |              if (preg_match('#' . sprintf($this->pager->getRewriteString(), '([0-9]+)') . '#', (string) $this->pager->getUrl())) | 
| 172 | 172 |                  $this->setUrl(new Url(preg_replace('#' . sprintf($this->pager->getRewriteString(), '([0-9]+)') . '#', sprintf($this->pager->getRewriteString(), $this->getIteration()), (string) $this->pager->getUrl()))); | 
| 173 | 173 |              else { | 
| 174 | - $url = clone $this->getPager()->getUrl(); | |
| 174 | + $url = clone $this->getPager()->getUrl(); | |
| 175 | 175 | $this->setUrl($url->appendToPath(sprintf($this->getPager()->getRewriteString(), $this->getIteration()))); | 
| 176 | 176 | } | 
| 177 | 177 | |
| @@ -72,8 +72,9 @@ discard block | ||
| 72 | 72 | * @return int | 
| 73 | 73 | */ | 
| 74 | 74 |      public function getOffset() { | 
| 75 | - if (!$this->offset) | |
| 76 | - $this->offset = ($this->getIndex() * $this->getPager()->getResultsPerPage()); | |
| 75 | +        if (!$this->offset) { | |
| 76 | + $this->offset = ($this->getIndex() * $this->getPager()->getResultsPerPage()); | |
| 77 | + } | |
| 77 | 78 | return $this->offset; | 
| 78 | 79 | } | 
| 79 | 80 | |
| @@ -82,8 +83,9 @@ discard block | ||
| 82 | 83 | * @return int | 
| 83 | 84 | */ | 
| 84 | 85 |      public function getResultCount() { | 
| 85 | - if (!$this->resultCount) | |
| 86 | - $this->resultCount = $this->isLastPage() ? $this->getPager()->getTotalResultCount() - $this->getOffset() : $this->getPager()->getResultsPerPage(); | |
| 86 | +        if (!$this->resultCount) { | |
| 87 | + $this->resultCount = $this->isLastPage() ? $this->getPager()->getTotalResultCount() - $this->getOffset() : $this->getPager()->getResultsPerPage(); | |
| 88 | + } | |
| 87 | 89 | return $this->resultCount; | 
| 88 | 90 | } | 
| 89 | 91 | |
| @@ -92,8 +94,9 @@ discard block | ||
| 92 | 94 | * @return bool | 
| 93 | 95 | */ | 
| 94 | 96 |      public function isFirstPage() { | 
| 95 | - if (!$this->isFirstPage) | |
| 96 | - $this->isFirstPage = ($this->getIteration() == 1); | |
| 97 | +        if (!$this->isFirstPage) { | |
| 98 | + $this->isFirstPage = ($this->getIteration() == 1); | |
| 99 | + } | |
| 97 | 100 | return $this->isFirstPage; | 
| 98 | 101 | } | 
| 99 | 102 | |
| @@ -102,8 +105,9 @@ discard block | ||
| 102 | 105 | * @return bool | 
| 103 | 106 | */ | 
| 104 | 107 |      public function isLastPage() { | 
| 105 | - if (!$this->isLastPage) | |
| 106 | - $this->isLastPage = ($this->getIteration() == $this->pager->getNbPages()); | |
| 108 | +        if (!$this->isLastPage) { | |
| 109 | + $this->isLastPage = ($this->getIteration() == $this->pager->getNbPages()); | |
| 110 | + } | |
| 107 | 111 | return $this->isLastPage; | 
| 108 | 112 | } | 
| 109 | 113 | |
| @@ -112,8 +116,9 @@ discard block | ||
| 112 | 116 | * @return bool | 
| 113 | 117 | */ | 
| 114 | 118 |      public function isCurrentPage() { | 
| 115 | - if (!$this->isCurrentPage) | |
| 116 | - $this->isCurrentPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration())); | |
| 119 | +        if (!$this->isCurrentPage) { | |
| 120 | + $this->isCurrentPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration())); | |
| 121 | + } | |
| 117 | 122 | return $this->isCurrentPage; | 
| 118 | 123 | } | 
| 119 | 124 | |
| @@ -122,8 +127,9 @@ discard block | ||
| 122 | 127 | * @return bool | 
| 123 | 128 | */ | 
| 124 | 129 |      public function isPreviousPage() { | 
| 125 | - if (!$this->isPreviousPage) | |
| 126 | - $this->isPreviousPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration() - 1)); | |
| 130 | +        if (!$this->isPreviousPage) { | |
| 131 | + $this->isPreviousPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration() - 1)); | |
| 132 | + } | |
| 127 | 133 | return $this->isPreviousPage; | 
| 128 | 134 | } | 
| 129 | 135 | |
| @@ -132,8 +138,9 @@ discard block | ||
| 132 | 138 | * @return bool | 
| 133 | 139 | */ | 
| 134 | 140 |      public function isNextPage() { | 
| 135 | - if (!$this->isNextPage) | |
| 136 | - $this->isNextPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration() + 1)); | |
| 141 | +        if (!$this->isNextPage) { | |
| 142 | + $this->isNextPage = ($this->getIteration() == ($this->pager->getCurrentPageIteration() + 1)); | |
| 143 | + } | |
| 137 | 144 | return $this->isNextPage; | 
| 138 | 145 | } | 
| 139 | 146 | |
| @@ -168,18 +175,17 @@ discard block | ||
| 168 | 175 |      public function getUrl() { | 
| 169 | 176 | |
| 170 | 177 |          if ($this->pager->getRewriteString()) { | 
| 171 | -            if (preg_match('#' . sprintf($this->pager->getRewriteString(), '([0-9]+)') . '#', (string) $this->pager->getUrl())) | |
| 172 | -                $this->setUrl(new Url(preg_replace('#' . sprintf($this->pager->getRewriteString(), '([0-9]+)') . '#', sprintf($this->pager->getRewriteString(), $this->getIteration()), (string) $this->pager->getUrl()))); | |
| 173 | -            else { | |
| 178 | +            if (preg_match('#' . sprintf($this->pager->getRewriteString(), '([0-9]+)') . '#', (string) $this->pager->getUrl())) { | |
| 179 | +                            $this->setUrl(new Url(preg_replace('#' . sprintf($this->pager->getRewriteString(), '([0-9]+)') . '#', sprintf($this->pager->getRewriteString(), $this->getIteration()), (string) $this->pager->getUrl()))); | |
| 180 | +            } else { | |
| 174 | 181 | $url = clone $this->getPager()->getUrl(); | 
| 175 | 182 | $this->setUrl($url->appendToPath(sprintf($this->getPager()->getRewriteString(), $this->getIteration()))); | 
| 176 | 183 | } | 
| 177 | 184 | |
| 185 | +        } else { | |
| 186 | + $this->setUrl(Url::NewInstance($this->pager->getUrl())->setParam($this->pager->getQueryParam(), $this->getIteration())); | |
| 178 | 187 | } | 
| 179 | 188 | |
| 180 | - else | |
| 181 | - $this->setUrl(Url::NewInstance($this->pager->getUrl())->setParam($this->pager->getQueryParam(), $this->getIteration())); | |
| 182 | - | |
| 183 | 189 | return $this->url; | 
| 184 | 190 | } | 
| 185 | 191 | |
| @@ -216,14 +222,13 @@ discard block | ||
| 216 | 222 | * @return mixed|null | 
| 217 | 223 | */ | 
| 218 | 224 |      public function offsetGet($offset) { | 
| 219 | - if (is_callable([$this, 'get' . $offset])) | |
| 220 | - return call_user_func([$this, 'get' . $offset]); | |
| 221 | - | |
| 222 | - elseif (is_callable([$this, $offset])) | |
| 223 | - return call_user_func([$this, $offset]); | |
| 224 | - | |
| 225 | - else | |
| 226 | - return null; | |
| 225 | +        if (is_callable([$this, 'get' . $offset])) { | |
| 226 | + return call_user_func([$this, 'get' . $offset]); | |
| 227 | +        } elseif (is_callable([$this, $offset])) { | |
| 228 | + return call_user_func([$this, $offset]); | |
| 229 | +        } else { | |
| 230 | + return null; | |
| 231 | + } | |
| 227 | 232 | } | 
| 228 | 233 | |
| 229 | 234 | /** | 
| @@ -36,44 +36,44 @@ discard block | ||
| 36 | 36 | */ | 
| 37 | 37 |  class Pager implements \IteratorAggregate, \Countable, \ArrayAccess, \JsonSerializable { | 
| 38 | 38 | |
| 39 | - const DEFAULT_PAGE_CLASS = '\\BenTools\\Pager\\Page'; | |
| 40 | - const DEFAULT_QUERY_PARAM = 'page'; | |
| 41 | - const DEFAULT_DELTA = 1; | |
| 39 | + const DEFAULT_PAGE_CLASS = '\\BenTools\\Pager\\Page'; | |
| 40 | + const DEFAULT_QUERY_PARAM = 'page'; | |
| 41 | + const DEFAULT_DELTA = 1; | |
| 42 | 42 | |
| 43 | 43 | /** | 
| 44 | 44 | * The class that will handle each page. | 
| 45 | 45 | * @var string | 
| 46 | 46 | */ | 
| 47 | - protected $pageClass = self::DEFAULT_PAGE_CLASS; | |
| 47 | + protected $pageClass = self::DEFAULT_PAGE_CLASS; | |
| 48 | 48 | |
| 49 | 49 | /** | 
| 50 | 50 | * @var int | 
| 51 | 51 | */ | 
| 52 | - protected $resultsPerPage = 0; | |
| 52 | + protected $resultsPerPage = 0; | |
| 53 | 53 | |
| 54 | 54 | /** | 
| 55 | 55 | * The total results count, all pages included. | 
| 56 | 56 | * @var int | 
| 57 | 57 | */ | 
| 58 | - protected $totalResultCount = 0; | |
| 58 | + protected $totalResultCount = 0; | |
| 59 | 59 | |
| 60 | 60 | /** | 
| 61 | 61 | * Current result count | 
| 62 | 62 | * @var int | 
| 63 | 63 | */ | 
| 64 | - protected $currentResultCount = 0; | |
| 64 | + protected $currentResultCount = 0; | |
| 65 | 65 | |
| 66 | 66 | /** | 
| 67 | 67 | * The Query param to check in the query string | 
| 68 | 68 | * @var string | 
| 69 | 69 | */ | 
| 70 | - protected $queryParam = self::DEFAULT_QUERY_PARAM; | |
| 70 | + protected $queryParam = self::DEFAULT_QUERY_PARAM; | |
| 71 | 71 | |
| 72 | 72 | /** | 
| 73 | 73 | * A print_f compatible string if the page information is in a rewrite string instead of the query string | 
| 74 | 74 | * @var | 
| 75 | 75 | */ | 
| 76 | - protected $rewriteString = ''; | |
| 76 | + protected $rewriteString = ''; | |
| 77 | 77 | |
| 78 | 78 | /** | 
| 79 | 79 | * The current page iteration | 
| @@ -85,18 +85,18 @@ discard block | ||
| 85 | 85 | * How many pages to show on each side when too many pages are rendered | 
| 86 | 86 | * @var int | 
| 87 | 87 | */ | 
| 88 | - protected $delta = self::DEFAULT_DELTA; | |
| 88 | + protected $delta = self::DEFAULT_DELTA; | |
| 89 | 89 | |
| 90 | 90 | /** | 
| 91 | 91 | * @var int | 
| 92 | 92 | */ | 
| 93 | - protected $nbPages = 0; | |
| 93 | + protected $nbPages = 0; | |
| 94 | 94 | |
| 95 | 95 | /** | 
| 96 | 96 | * The current offset (useful for a LIMIT offset, max in a SQL clause) | 
| 97 | 97 | * @var int | 
| 98 | 98 | */ | 
| 99 | - protected $currentOffset = 0; | |
| 99 | + protected $currentOffset = 0; | |
| 100 | 100 | |
| 101 | 101 | /** | 
| 102 | 102 | * The Url to begin with | 
| @@ -108,7 +108,7 @@ discard block | ||
| 108 | 108 | * The pages rendered by the object (if there's a delta and too many pages, not all pages will be shown) | 
| 109 | 109 | * @var array | 
| 110 | 110 | */ | 
| 111 | - protected $pages = []; | |
| 111 | + protected $pages = []; | |
| 112 | 112 | |
| 113 | 113 |      public function __construct($url = null, $resultsPerPage = null, $totalResultCount = null, $queryParam = self::DEFAULT_QUERY_PARAM, $rewriteString = null, $currentPageIteration = null, $delta = self::DEFAULT_DELTA) { | 
| 114 | 114 | |
| @@ -274,19 +274,19 @@ discard block | ||
| 274 | 274 | if (!is_integer($this->totalResultCount)) | 
| 275 | 275 | throw new PagerException(get_called_class() . "::setTotalResultCount has to be called first."); | 
| 276 | 276 | |
| 277 | - $this->pages = []; | |
| 277 | + $this->pages = []; | |
| 278 | 278 | |
| 279 | 279 | $this->setNbPages((int) ceil($this->getTotalResultCount() / $this->getResultsPerPage())); | 
| 280 | 280 | |
| 281 | 281 | # Case of a delta, e.g. << 1 ... 6 [7] 8 ... 15 >> | 
| 282 | 282 |          if ($this->getDelta()) { | 
| 283 | 283 | |
| 284 | - $p = 0; | |
| 284 | + $p = 0; | |
| 285 | 285 | |
| 286 | 286 | # Add first page, current page and last page | 
| 287 | - $this->pages[] = $this->getPageInstance(1); | |
| 288 | - $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration()); | |
| 289 | - $this->pages[] = $this->getPageInstance($this->getNbPages()); | |
| 287 | + $this->pages[] = $this->getPageInstance(1); | |
| 288 | + $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration()); | |
| 289 | + $this->pages[] = $this->getPageInstance($this->getNbPages()); | |
| 290 | 290 | |
| 291 | 291 | # Calculate delta | 
| 292 | 292 |              for ($i = 1; $i <= $this->getDelta(); $i++) { | 
| @@ -313,7 +313,7 @@ discard block | ||
| 313 | 313 | } | 
| 314 | 314 |          else { | 
| 315 | 315 | for ($i = 1; $i <= $this->getNbPages(); $i++) | 
| 316 | - $this->pages[] = $this->getPageInstance($i); | |
| 316 | + $this->pages[] = $this->getPageInstance($i); | |
| 317 | 317 | } | 
| 318 | 318 | $this->pages = array_unique((array) $this->pages); | 
| 319 | 319 | sort($this->pages); | 
| @@ -467,7 +467,7 @@ discard block | ||
| 467 | 467 | * @return PageInterface | 
| 468 | 468 | */ | 
| 469 | 469 |      public function getPageInstance($iteration) { | 
| 470 | - $class = $this->pageClass; | |
| 470 | + $class = $this->pageClass; | |
| 471 | 471 | return new $class($this, (int) $iteration); | 
| 472 | 472 | } | 
| 473 | 473 | |
| @@ -112,17 +112,15 @@ discard block | ||
| 112 | 112 | |
| 113 | 113 |      public function __construct($url = null, $resultsPerPage = null, $totalResultCount = null, $queryParam = self::DEFAULT_QUERY_PARAM, $rewriteString = null, $currentPageIteration = null, $delta = self::DEFAULT_DELTA) { | 
| 114 | 114 | |
| 115 | - if ($url instanceof Url) | |
| 116 | - $this->setUrl($url); | |
| 117 | - | |
| 118 | - elseif ($url) | |
| 119 | - $this->setUrl(new Url($url)); | |
| 120 | - | |
| 121 | - elseif (isset($_SERVER['REQUEST_URI'])) | |
| 122 | - $this->setUrl(new Url($_SERVER['REQUEST_URI'])); | |
| 123 | - | |
| 124 | - else | |
| 125 | -            $this->setUrl(new Url('/')); | |
| 115 | +        if ($url instanceof Url) { | |
| 116 | + $this->setUrl($url); | |
| 117 | +        } elseif ($url) { | |
| 118 | + $this->setUrl(new Url($url)); | |
| 119 | +        } elseif (isset($_SERVER['REQUEST_URI'])) { | |
| 120 | + $this->setUrl(new Url($_SERVER['REQUEST_URI'])); | |
| 121 | +        } else { | |
| 122 | +                    $this->setUrl(new Url('/')); | |
| 123 | + } | |
| 126 | 124 | |
| 127 | 125 | $this -> setResultsPerPage($resultsPerPage) | 
| 128 | 126 | -> setTotalResultCount($totalResultCount) | 
| @@ -184,10 +182,11 @@ discard block | ||
| 184 | 182 | */ | 
| 185 | 183 |      public function getCurrentPageIteration() { | 
| 186 | 184 |          if (!$this->currentPageIteration) { | 
| 187 | -            if (!is_null($this->rewriteString) && preg_match('#' . sprintf($this->rewriteString, '([0-9]+)') . '#', (string) $this->url, $matches)) | |
| 188 | - $this->currentPageIteration = (int) ((isset($matches[1]) && $matches[1] > 0) ? $matches[1] : 1); | |
| 189 | - else | |
| 190 | - $this->currentPageIteration = ($this->url->getParam($this->queryParam)) ? (int) $this->url->getParam($this->queryParam) : 1; | |
| 185 | +            if (!is_null($this->rewriteString) && preg_match('#' . sprintf($this->rewriteString, '([0-9]+)') . '#', (string) $this->url, $matches)) { | |
| 186 | + $this->currentPageIteration = (int) ((isset($matches[1]) && $matches[1] > 0) ? $matches[1] : 1); | |
| 187 | +            } else { | |
| 188 | + $this->currentPageIteration = ($this->url->getParam($this->queryParam)) ? (int) $this->url->getParam($this->queryParam) : 1; | |
| 189 | + } | |
| 191 | 190 | } | 
| 192 | 191 | return (int) $this->currentPageIteration; | 
| 193 | 192 | |
| @@ -234,10 +233,11 @@ discard block | ||
| 234 | 233 | * @return Page Instance | 
| 235 | 234 | */ | 
| 236 | 235 |      public function getPreviousPage() { | 
| 237 | - if ($this->getCurrentPageIteration() - 1 >= 1) | |
| 238 | - return $this->getPageInstance($this->getCurrentPageIteration() - 1); | |
| 239 | - else | |
| 240 | - return $this->getFirstPage(); | |
| 236 | +        if ($this->getCurrentPageIteration() - 1 >= 1) { | |
| 237 | + return $this->getPageInstance($this->getCurrentPageIteration() - 1); | |
| 238 | +        } else { | |
| 239 | + return $this->getFirstPage(); | |
| 240 | + } | |
| 241 | 241 | } | 
| 242 | 242 | |
| 243 | 243 | /** | 
| @@ -246,10 +246,11 @@ discard block | ||
| 246 | 246 | * @return Page Instance | 
| 247 | 247 | */ | 
| 248 | 248 |      public function getNextPage() { | 
| 249 | - if ($this->getCurrentPageIteration() + 1 <= $this->getNbPages()) | |
| 250 | - return $this->getPageInstance($this->getCurrentPageIteration() + 1); | |
| 251 | - else | |
| 252 | - return $this->getLastPage(); | |
| 249 | +        if ($this->getCurrentPageIteration() + 1 <= $this->getNbPages()) { | |
| 250 | + return $this->getPageInstance($this->getCurrentPageIteration() + 1); | |
| 251 | +        } else { | |
| 252 | + return $this->getLastPage(); | |
| 253 | + } | |
| 253 | 254 | } | 
| 254 | 255 | |
| 255 | 256 | /** | 
| @@ -269,10 +270,12 @@ discard block | ||
| 269 | 270 | */ | 
| 270 | 271 |      public function run() { | 
| 271 | 272 | |
| 272 | - if (!$this->resultsPerPage) | |
| 273 | - throw new PagerException(get_called_class() . "::setResultsPerPage has to be called first."); | |
| 274 | - if (!is_integer($this->totalResultCount)) | |
| 275 | - throw new PagerException(get_called_class() . "::setTotalResultCount has to be called first."); | |
| 273 | +        if (!$this->resultsPerPage) { | |
| 274 | + throw new PagerException(get_called_class() . "::setResultsPerPage has to be called first."); | |
| 275 | + } | |
| 276 | +        if (!is_integer($this->totalResultCount)) { | |
| 277 | + throw new PagerException(get_called_class() . "::setTotalResultCount has to be called first."); | |
| 278 | + } | |
| 276 | 279 | |
| 277 | 280 | $this->pages = []; | 
| 278 | 281 | |
| @@ -293,27 +296,31 @@ discard block | ||
| 293 | 296 | |
| 294 | 297 | #### SUPERIOR DELTA #### | 
| 295 | 298 | # If the next page doesn't overtstep the last one | 
| 296 | - if ($this->getCurrentPageIteration() + $i <= $this->getNbPages()) | |
| 297 | - $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration() + $i); | |
| 299 | +                if ($this->getCurrentPageIteration() + $i <= $this->getNbPages()) { | |
| 300 | + $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration() + $i); | |
| 301 | + } | |
| 298 | 302 | |
| 299 | 303 | # Otherwise, we put the remaining delta before, providing it doesn't overstep the 1st one | 
| 300 | - elseif ($this->getCurrentPageIteration() - $i >= 1) | |
| 301 | - $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration() - $i); | |
| 304 | +                elseif ($this->getCurrentPageIteration() - $i >= 1) { | |
| 305 | + $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration() - $i); | |
| 306 | + } | |
| 302 | 307 | |
| 303 | 308 | #### INFERIOR DELTA #### | 
| 304 | 309 | # If the previous page doesn't overstep the 1st one | 
| 305 | - if ($this->getCurrentPageIteration() - $i >= 1) | |
| 306 | - $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration() - $i); | |
| 310 | +                if ($this->getCurrentPageIteration() - $i >= 1) { | |
| 311 | + $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration() - $i); | |
| 312 | + } | |
| 307 | 313 | |
| 308 | 314 | # Otherwise, we put the remaining delta before, providing it doesn't overstep the last one | 
| 309 | - elseif ($this->getCurrentPageIteration() + $i <= $this->getNbPages()) | |
| 310 | - $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration() + $i); | |
| 315 | +                elseif ($this->getCurrentPageIteration() + $i <= $this->getNbPages()) { | |
| 316 | + $this->pages[] = $this->getPageInstance($this->getCurrentPageIteration() + $i); | |
| 317 | + } | |
| 311 | 318 | |
| 312 | 319 | } | 
| 313 | - } | |
| 314 | -        else { | |
| 315 | - for ($i = 1; $i <= $this->getNbPages(); $i++) | |
| 316 | - $this->pages[] = $this->getPageInstance($i); | |
| 320 | +        } else { | |
| 321 | +            for ($i = 1; $i <= $this->getNbPages(); $i++) { | |
| 322 | + $this->pages[] = $this->getPageInstance($i); | |
| 323 | + } | |
| 317 | 324 | } | 
| 318 | 325 | $this->pages = array_unique((array) $this->pages); | 
| 319 | 326 | sort($this->pages); | 
| @@ -487,17 +494,15 @@ discard block | ||
| 487 | 494 | */ | 
| 488 | 495 |      public function offsetGet($offset) { | 
| 489 | 496 | |
| 490 | - if (is_numeric($offset)) | |
| 491 | - return array_key_exists($offset, $this->getPages()) ? $this->getPages()[$offset] : null; | |
| 492 | - | |
| 493 | - elseif (is_callable([$this, 'get' . $offset])) | |
| 494 | - return call_user_func([$this, 'get' . $offset]); | |
| 495 | - | |
| 496 | - elseif (is_callable([$this, 'is' . $offset])) | |
| 497 | - return call_user_func([$this, 'is' . $offset]); | |
| 498 | - | |
| 499 | - else | |
| 500 | - return null; | |
| 497 | +        if (is_numeric($offset)) { | |
| 498 | + return array_key_exists($offset, $this->getPages()) ? $this->getPages()[$offset] : null; | |
| 499 | +        } elseif (is_callable([$this, 'get' . $offset])) { | |
| 500 | + return call_user_func([$this, 'get' . $offset]); | |
| 501 | +        } elseif (is_callable([$this, 'is' . $offset])) { | |
| 502 | + return call_user_func([$this, 'is' . $offset]); | |
| 503 | +        } else { | |
| 504 | + return null; | |
| 505 | + } | |
| 501 | 506 | } | 
| 502 | 507 | |
| 503 | 508 | /** |