Completed
Push — master ( ad2c0d...49711d )
by Yaro
10:29
created

PaginateTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 33
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRawPerPage() 0 4 1
A paginate() 0 16 4
getPerPageParam() 0 1 ?
setPerPageParam() 0 1 ?
repo() 0 1 ?
1
<?php
2
3
namespace Yaro\Jarboe\Table\CrudTraits;
4
5
trait PaginateTrait
6
{
7
    private $rawPerPage;
8
9
    public function getRawPerPage()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
10
    {
11
        return $this->rawPerPage;
12
    }
13
14
    /**
15
     * @param int|array $perPage
16
     */
17
    public function paginate($perPage)
18
    {
19
        $this->rawPerPage = $perPage;
20
21
        $storedPerPage = $this->getPerPageParam();
22
        if (is_array($perPage)) {
23
            $perPage = array_shift($perPage);
24
        }
25
        if (!$storedPerPage) {
26
            $this->setPerPageParam($perPage ?: $this->repo()->perPage());
27
            $storedPerPage = $perPage;
28
        }
29
        $this->repo()->perPage($storedPerPage);
30
31
        return $this;
32
    }
33
34
    abstract public function getPerPageParam();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
35
    abstract public function setPerPageParam($perPage);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
36
    abstract public function repo();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
37
}
38