Total Complexity | 9 |
Total Lines | 87 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class Page |
||
6 | { |
||
7 | |||
8 | const DEFAULT_SIZE = 10; |
||
9 | |||
10 | /** |
||
11 | * The actual data. |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | private $data; |
||
16 | |||
17 | /** |
||
18 | * The amount of total items on this page. |
||
19 | * |
||
20 | * @var int |
||
21 | */ |
||
22 | private $total; |
||
23 | |||
24 | /** |
||
25 | * The index of the first index on this page. (defaults to 0) |
||
26 | * |
||
27 | * @var int |
||
28 | */ |
||
29 | private $from; |
||
30 | |||
31 | /** |
||
32 | * Page constructor. |
||
33 | * |
||
34 | * @param array $data |
||
35 | * @param int|null $total |
||
36 | * @param int $from |
||
37 | */ |
||
38 | public function __construct(array $data, $total = null, $from = 0) |
||
39 | { |
||
40 | $this->data = $this->keyData($data, $from); |
||
41 | $this->total = $total ?: count($data); |
||
42 | $this->from = $from; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @return mixed |
||
47 | */ |
||
48 | public function getFirst() |
||
49 | { |
||
50 | return !empty($this->data) ? head($this->data) : null; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @return array |
||
55 | */ |
||
56 | public function getData() |
||
57 | { |
||
58 | return $this->data; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return int |
||
63 | */ |
||
64 | public function getTotal() |
||
65 | { |
||
66 | return $this->total; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return int |
||
71 | */ |
||
72 | public function getFrom() |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param array $data |
||
79 | * @param int $from |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | private function keyData(array $data, $from) |
||
92 | } |
||
93 | } |
||
94 |