| Total Complexity | 6 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | class ArrayPaginator implements PaginatorInterface |
||
| 26 | { |
||
| 27 | |||
| 28 | use PaginatorTrait; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | private $items; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param array $items |
||
| 37 | * @param int $perPage |
||
| 38 | * @param int $page |
||
| 39 | */ |
||
| 40 | public function __construct(array $items, int $perPage, int $page = 1) |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @inheritDoc |
||
| 50 | */ |
||
| 51 | public function data(): array |
||
| 52 | { |
||
| 53 | return array_slice( |
||
| 54 | $this->items, |
||
| 55 | ($this->page - 1) * $this->perPage, |
||
| 56 | $this->perPage |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @inheritDoc |
||
| 62 | */ |
||
| 63 | public function firstItem() |
||
| 64 | { |
||
| 65 | $data = $this->data(); |
||
| 66 | |||
| 67 | if (empty($data)) { |
||
| 68 | return null; |
||
| 69 | } |
||
| 70 | |||
| 71 | return reset($data); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @inheritDoc |
||
| 76 | */ |
||
| 77 | public function lastItem() |
||
| 86 | } |
||
| 87 | } |