Paginator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 91
ccs 16
cts 16
cp 1
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaginator() 0 3 1
A __construct() 0 3 1
A getPerPage() 0 3 1
A getTotal() 0 3 1
A getLastPage() 0 3 1
A getUrl() 0 3 1
A getCurrentPage() 0 3 1
A getCount() 0 3 1
1
<?php
2
3
namespace Rexlabs\Laravel\Smokescreen\Pagination;
4
5
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
6
use Rexlabs\Smokescreen\Pagination\PaginatorInterface;
7
8
/**
9
 * Provides a bridge between Laravel's LengthAwarePaginator and Smokescreen's pagination interface.
10
 * Code is heavily based on `thephpleague/fractal` package.
11
 */
12
class Paginator implements PaginatorInterface
13
{
14
    /**
15
     * The paginator instance.
16
     *
17
     * @var \Illuminate\Contracts\Pagination\LengthAwarePaginator
18
     */
19
    protected $paginator;
20
21
    /**
22
     * Create a new illuminate pagination adapter.
23
     *
24
     * @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
25
     *
26
     * @return void
27
     */
28 4
    public function __construct(LengthAwarePaginator $paginator)
29
    {
30 4
        $this->paginator = $paginator;
31
    }
32
33
    /**
34
     * Get the current page.
35
     *
36
     * @return int
37
     */
38 3
    public function getCurrentPage(): int
39
    {
40 3
        return $this->paginator->currentPage();
41
    }
42
43
    /**
44
     * Get the last page.
45
     *
46
     * @return int
47
     */
48 5
    public function getLastPage(): int
49
    {
50 5
        return $this->paginator->lastPage();
51
    }
52
53
    /**
54
     * Get the total.
55
     *
56
     * @return int
57
     */
58 4
    public function getTotal(): int
59
    {
60 4
        return $this->paginator->total();
61
    }
62
63
    /**
64
     * Get the count.
65
     *
66
     * @return int
67
     */
68 5
    public function getCount(): int
69
    {
70 5
        return $this->paginator->count();
71
    }
72
73
    /**
74
     * Get the number per page.
75
     *
76
     * @return int
77
     */
78 5
    public function getPerPage(): int
79
    {
80 5
        return $this->paginator->perPage();
81
    }
82
83
    /**
84
     * Get the url for the given page.
85
     *
86
     * @param int $page
87
     *
88
     * @return string
89
     */
90 1
    public function getUrl($page): string
91
    {
92 1
        return $this->paginator->url($page);
93
    }
94
95
    /**
96
     * Get the paginator instance.
97
     *
98
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
99
     */
100 1
    public function getPaginator(): LengthAwarePaginator
101
    {
102 1
        return $this->paginator;
103
    }
104
}
105