| Conditions | 4 |
| Paths | 3 |
| Total Lines | 23 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 38 | public function createPaginator(string $parameter, int $limit = 25): PaginatorInterface |
||
| 39 | { |
||
| 40 | if (!$this->container->has(ServerRequestInterface::class)) { |
||
| 41 | throw new ScopeException("Unable to create paginator, no request scope found"); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var array $query |
||
| 46 | */ |
||
| 47 | $query = $this->container->get(ServerRequestInterface::class)->getQueryParams(); |
||
| 48 | |||
| 49 | //Getting page number |
||
| 50 | $page = 0; |
||
| 51 | if (!empty($query[$parameter]) && is_scalar($query[$parameter])) { |
||
| 52 | $page = (int)$query[$parameter]; |
||
| 53 | } |
||
| 54 | |||
| 55 | //Initiating paginator |
||
| 56 | return $this->container->make( |
||
| 57 | Paginator::class, |
||
| 58 | compact('limit', 'parameter') |
||
| 59 | )->withPage($page); |
||
| 60 | } |
||
| 61 | } |