PaginationRequest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 8
c 5
b 0
f 0
lcom 1
cbo 0
dl 0
loc 50
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getOffset() 0 4 3
A getLimit() 0 4 3
A getCurrentPage() 0 4 1
1
<?php
2
3
namespace Alchemy\RestBundle\Rest\Request;
4
5
use Alchemy\Rest\Request\PaginationOptions;
6
7
/**
8
 * Class PaginationRequest
9
 * @package Alchemy\RestBundle\Rest\Request
10
 */
11
class PaginationRequest implements PaginationOptions
12
{
13
14
    /**
15
     * @var int
16
     */
17
    private $offset;
18
19
    /**
20
     * @var int
21
     */
22
    private $limit;
23
24
    /**
25
     * @param int $offset
26
     * @param int $limit
27
     */
28 30
    public function __construct($offset, $limit)
29
    {
30 30
        $this->offset = (int) $offset;
31 30
        $this->limit = (int) $limit;
32 30
    }
33
34
    /**
35
     * @param null|int $defaultValue
36
     * @return int
37
     */
38 22
    public function getOffset($defaultValue = null)
39
    {
40 22
        return ($this->offset > 0 || $defaultValue === null) ? $this->offset : (int) $defaultValue;
41
    }
42
43
    /**
44
     * @param null|int $defaultValue
45
     * @return int
46
     */
47 22
    public function getLimit($defaultValue = null)
48
    {
49 22
        return ($this->limit > 0 || $defaultValue === null) ? $this->limit : (int) $defaultValue;
50
    }
51
52
    /**
53
     * @param int $defaultPageSize
54
     * @return int
55
     */
56 12
    public function getCurrentPage($defaultPageSize = 10)
57
    {
58 12
        return (int)floor($this->getOffset(0) / max(1, $this->getLimit($defaultPageSize))) + 1;
59
    }
60
}
61