WithPagination   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 67
ccs 0
cts 32
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getPerPage() 0 4 1
A setPerPage() 0 6 1
A getPageName() 0 4 1
A setPageName() 0 6 1
A paginate() 0 6 1
A disablePagination() 0 4 1
A isPagination() 0 4 1
1
<?php
2
3
namespace Sco\Admin\Display\Concerns;
4
5
trait WithPagination
6
{
7
    protected $perPage = 20;
8
9
    protected $pageName = 'page';
10
11
    /**
12
     * @return int
13
     */
14
    public function getPerPage(): int
15
    {
16
        return $this->perPage;
17
    }
18
19
    /**
20
     * @param int $perPage
21
     * @return $this
22
     */
23
    public function setPerPage(int $perPage)
24
    {
25
        $this->perPage = $perPage;
26
27
        return $this;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getPageName(): string
34
    {
35
        return $this->pageName;
36
    }
37
38
    /**
39
     * @param string $pageName
40
     * @return $this
41
     */
42
    public function setPageName(string $pageName)
43
    {
44
        $this->pageName = $pageName;
45
46
        return $this;
47
    }
48
49
    public function paginate()
50
    {
51
        return $this->getQuery()
0 ignored issues
show
Bug introduced by
It seems like getQuery() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
52
            ->paginate($this->getPerPage(), ['*'], $this->getPageName())
53
            ->appends(request()->except($this->getPageName()));
54
    }
55
56
    /**
57
     * @return $this
58
     */
59
    public function disablePagination()
60
    {
61
        return $this->setPerPage(0);
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function isPagination()
68
    {
69
        return $this->getPerPage() > 0;
70
    }
71
}
72