PaginationResult   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 97
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getIterator() 0 4 2
A count() 0 4 1
A render() 0 6 1
1
<?php
2
3
namespace mav3rick177\RapidPagination\Base;
4
5
/**
6
 * Class PaginationResult
7
 */
8
class PaginationResult implements \IteratorAggregate, \Countable
9
{
10
    /**
11
     * @var mixed
12
     */
13
    public $records;
14
15
    /**
16
     * @var null|bool
17
     */
18
    public $hasPrevious;
19
20
    /**
21
     * @var null|mixed
22
     */
23
    public $previousCursor;
24
25
    /**
26
     * @var null|bool
27
     */
28
    public $hasNext;
29
30
    /**
31
     * @var null|mixed
32
     */
33
    public $nextCursor;
34
35
    /**
36
     * @var null|mixed
37
     */
38
    public $previousUrl;
39
40
    /**
41
     * @var null|mixed
42
     */
43
    public $nextUrl;
44
45
    /**
46
     * @var null|mixed
47
     */
48
    public $tab;
49
50
    /**
51
     * @var null|mixed
52
     */
53
    public $query = [];
54
55
    /**
56
     * PaginationResult constructor.
57
     * Merge $meta entries into $this.
58
     *
59
     * @param mixed $rows
60
     * @param array $meta
61
     */
62
    public function __construct($rows, array $meta)
63
    {
64
        $this->records = $rows;
65
        foreach ($meta as $key => $value) {
66
            $this->$key = $value;
67
        }
68
    }
69
70
    /**
71
     * Get iterator of records.
72
     *
73
     * @return \ArrayIterator|\Traversable
74
     */
75
    public function getIterator()
76
    {
77
        return $this->records instanceof \Traversable ? $this->records : new \ArrayIterator($this->records);
78
    }
79
80
    /**
81
     * Count records.
82
     *
83
     * @return int
84
     * @see https://wiki.php.net/rfc/counting_non_countables
85
     */
86
    public function count()
87
    {
88
        return count($this->records);
89
    }
90
91
    /**
92
     * Render the paginator using the given view.
93
     *
94
     * @param  string|null  $view
95
     * @param  array  $data
96
     * @return \Illuminate\Contracts\Support\Htmlable
97
     */
98
    public function render($view = 'rapid-pagination::default', $data = [])
99
    {
100
        return view($view, array_merge($data, [
101
            'paginator' => $this,
102
        ]));
103
    }
104
}
105