Total Complexity | 7 |
Total Lines | 73 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
26 | class ArrayPaginator implements PaginatorInterface |
||
27 | { |
||
28 | |||
29 | use PaginatorTrait; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private $items; |
||
35 | |||
36 | /** |
||
37 | * @param array $items |
||
38 | * @param int $perPage |
||
39 | * @param int $page |
||
40 | */ |
||
41 | public function __construct(array $items, int $perPage, int $page = 1) |
||
42 | { |
||
43 | $this->initialize($perPage, $page); |
||
44 | $this->items = $items; |
||
45 | $this->total = count($items); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param array $params |
||
50 | * @return PaginatorInterface |
||
51 | */ |
||
52 | public static function fromArray(array $params): PaginatorInterface |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @inheritDoc |
||
63 | */ |
||
64 | public function data(): array |
||
65 | { |
||
66 | return array_slice( |
||
67 | $this->items, |
||
68 | ($this->page - 1) * $this->perPage, |
||
69 | $this->perPage |
||
70 | ); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @inheritDoc |
||
75 | */ |
||
76 | public function firstItem() |
||
77 | { |
||
78 | $data = $this->data(); |
||
79 | |||
80 | if (empty($data)) { |
||
81 | return null; |
||
82 | } |
||
83 | |||
84 | return reset($data); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @inheritDoc |
||
89 | */ |
||
90 | public function lastItem() |
||
99 | } |
||
100 | } |