| Conditions | 4 |
| Paths | 3 |
| Total Lines | 17 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 31 | 3 | public function createPaginator(string $parameter, int $limit = 25): PaginatorInterface |
|
| 32 | { |
||
| 33 | 3 | if (!$this->container->has(ServerRequestInterface::class)) { |
|
| 34 | 1 | throw new ScopeException('Unable to create paginator, no request scope found'); |
|
| 35 | } |
||
| 36 | /** |
||
| 37 | * @var array $query |
||
| 38 | */ |
||
| 39 | 2 | $query = $this->container->get(ServerRequestInterface::class)->getQueryParams(); |
|
| 40 | |||
| 41 | //Getting page number |
||
| 42 | 2 | $page = 0; |
|
| 43 | 2 | if (!empty($query[$parameter]) && \is_scalar($query[$parameter])) { |
|
| 44 | 1 | $page = (int) $query[$parameter]; |
|
| 45 | } |
||
| 46 | |||
| 47 | 2 | return $this->factory->make(Paginator::class, ['limit' => $limit, 'parameter' => $parameter])->withPage($page); |
|
| 48 | } |
||
| 50 |