Pagination   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 83
c 1
b 0
f 0
wmc 8
lcom 1
cbo 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getOffset() 0 4 1
A getPage() 0 4 1
A setPage() 0 5 1
A getCount() 0 4 1
A setCount() 0 5 2
1
<?php
2
3
namespace Netdudes\DataSourceryBundle\Query;
4
5
/**
6
 * Defines a status of pagination
7
 */
8
class Pagination
9
{
10
    /**
11
     * Default pagination count (elements per page)
12
     */
13
    const DEFAULT_COUNT = 20;
14
15
    /**
16
     * The page
17
     *
18
     * @var int
19
     */
20
    private $page;
21
22
    /**
23
     * Elements per page
24
     *
25
     * @var int
26
     */
27
    private $count;
28
29
    /**
30
     * Calculated: page * count
31
     *
32
     * @var int
33
     */
34
    private $offset;
35
36
    /**
37
     * @param $page  int 0-indexed page
38
     * @param $count int Items per page
39
     */
40
    public function __construct($page = 0, $count = self::DEFAULT_COUNT)
41
    {
42
        $this->page = $page;
43
        $this->count = $count > 0 ? $count : self::DEFAULT_COUNT;
44
45
        // The item offset form the beginning of the item collection
46
        $this->offset = $page * $count;
47
    }
48
49
    /**
50
     * @return mixed
51
     */
52
    public function getOffset()
53
    {
54
        return $this->offset;
55
    }
56
57
    /**
58
     * @return mixed
59
     */
60
    public function getPage()
61
    {
62
        return $this->page;
63
    }
64
65
    /**
66
     * @param int $page
67
     */
68
    public function setPage($page)
69
    {
70
        $this->page = $page;
71
        $this->offset = $this->page * $this->count;
72
    }
73
74
    /**
75
     * @return mixed
76
     */
77
    public function getCount()
78
    {
79
        return $this->count;
80
    }
81
82
    /**
83
     * @param int $count
84
     */
85
    public function setCount($count)
86
    {
87
        $this->count = $count > 0 ? $count : self::DEFAULT_COUNT;
88
        $this->offset = $this->page * $this->count;
89
    }
90
}
91