Completed
Push — master ( ea613e...54b4d6 )
by Iqbal
02:33
created

Pagination::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Borobudur-Cqrs package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Cqrs\ReadModel\Storage\Finder;
12
13
/**
14
 * @author      Iqbal Maulana <[email protected]>
15
 * @created     3/25/16
16
 */
17
class Pagination
18
{
19
    /**
20
     * @var int
21
     */
22
    public $limit;
23
24
    /**
25
     * @var int
26
     */
27
    public $current;
28
29
    /**
30
     * @var int
31
     */
32
    public $prev = null;
33
34
    /**
35
     * @var int
36
     */
37
    public $next = null;
38
39
    /**
40
     * @var int
41
     */
42
    public $pages = 0;
43
44
    /**
45
     * @var int
46
     */
47
    public $total;
48
49
    /**
50
     * Constructor.
51
     *
52
     * @param int $limit
53
     * @param int $current
54
     */
55
    public function __construct($limit, $current)
56
    {
57
        $this->limit = $limit;
58
        $this->current = $current;
59
60
        if (1 !== $current) {
61
            $this->prev = $current - 1;
62
        }
63
    }
64
65
    /**
66
     * @param int $total
67
     */
68
    public function calc($total)
69
    {
70
        $this->pages = ceil($total / $this->limit);
0 ignored issues
show
Documentation Bug introduced by
The property $pages was declared of type integer, but ceil($total / $this->limit) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
71
72
        if ($this->current < $this->pages) {
73
            $this->next = $this->current + 1;
74
        }
75
    }
76
77
    /**
78
     * @return array
79
     */
80
    public function serialize()
81
    {
82
        return array(
83
            'prev'    => $this->prev,
84
            'current' => $this->current,
85
            'next'    => $this->next,
86
            'pages'   => $this->pages,
87
        );
88
    }
89
}
90