Pagination::items()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Pagination items
4
 * User: moyo
5
 * Date: 2018/4/19
6
 * Time: 2:41 PM
7
 */
8
9
namespace Carno\Database\SQL\Paginator;
10
11
final class Pagination
12
{
13
    /**
14
     * @var int
15
     */
16
    private $total = 0;
17
18
    /**
19
     * @var int
20
     */
21
    private $size = 0;
22
23
    /**
24
     * @var int
25
     */
26
    private $prev = 1;
27
28
    /**
29
     * @var int
30
     */
31
    private $page = 1;
32
33
    /**
34
     * @var int
35
     */
36
    private $next = 1;
37
38
    /**
39
     * @var int
40
     */
41
    private $last = 1;
42
43
    /**
44
     * @var array
45
     */
46
    private $items = [];
47
48
    /**
49
     * Pagination constructor.
50
     * @param int $total
51
     * @param int $size
52
     * @param int $prev
53
     * @param int $page
54
     * @param int $next
55
     * @param int $last
56
     * @param array $items
57
     */
58
    public function __construct(int $total, int $size, int $prev, int $page, int $next, int $last, array $items)
59
    {
60
        $this->total = $total;
61
        $this->size = $size;
62
        $this->prev = $prev;
63
        $this->page = $page;
64
        $this->next = $next;
65
        $this->last = $last;
66
        $this->items = $items;
67
    }
68
69
    /**
70
     * @return int
71
     */
72
    public function total() : int
73
    {
74
        return $this->total;
75
    }
76
77
    /**
78
     * @return int
79
     */
80
    public function size() : int
81
    {
82
        return $this->size;
83
    }
84
85
    /**
86
     * @return int
87
     */
88
    public function prev() : int
89
    {
90
        return $this->prev;
91
    }
92
93
    /**
94
     * @return int
95
     */
96
    public function page() : int
97
    {
98
        return $this->page;
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public function next() : int
105
    {
106
        return $this->next;
107
    }
108
109
    /**
110
     * @return int
111
     */
112
    public function last() : int
113
    {
114
        return $this->last;
115
    }
116
117
    /**
118
     * @return array
119
     */
120
    public function items() : array
121
    {
122
        return $this->items;
123
    }
124
125
    /**
126
     * @param object $target
127
     * @return mixed
128
     */
129
    public function export(object $target) : object
130
    {
131
        foreach (['total', 'size', 'prev', 'page', 'next', 'last'] as $key) {
132
            if (method_exists($target, $func = sprintf('set%s', ucfirst($key)))) {
133
                $target->$func($this->$key);
134
            }
135
        }
136
137
        return $target;
138
    }
139
}
140