Result::getResults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Nord\Lumen\Search;
2
3
class Result
4
{
5
6
    /**
7
     * @var array
8
     */
9
    private $results = [];
10
11
    /**8
12
     * @var int
13
     */
14
    private $totalCount;
15
16
    /**
17
     * @var int
18
     */
19
    private $pageNumber;
20
21
    /**
22
     * @var int
23
     */
24
    private $pageSize;
25
26
27
    /**
28
     * Result constructor.
29
     *
30
     * @param array    $results
31
     * @param int|null $totalCount
32
     * @param int|null $pageNumber
33
     * @param int|null $pageSize
34
     */
35
    public function __construct(array $results, $totalCount = null, $pageNumber = null, $pageSize = null)
36
    {
37
        $this->results    = $results;
38
        $this->totalCount = $totalCount;
39
        $this->pageNumber = $pageNumber;
40
        $this->pageSize   = $pageSize;
41
    }
42
43
44
    /**
45
     * @return int
46
     */
47
    public function calculatePageCount()
48
    {
49
        return $this->totalCount > 0 && $this->pageSize > 0 ? ceil($this->totalCount / $this->pageSize) : 1;
50
    }
51
52
53
    /**
54
     * @return array
55
     */
56
    public function getResults()
57
    {
58
        return $this->results;
59
    }
60
61
62
    /**
63
     * @return int
64
     */
65
    public function getTotalCount()
66
    {
67
        return $this->totalCount !== null ? $this->totalCount : count($this->results);
68
    }
69
70
71
    /**
72
     * @return int
73
     */
74
    public function getPageNumber()
75
    {
76
        return $this->pageNumber;
77
    }
78
79
80
    /**
81
     * @return int
82
     */
83
    public function getPageSize()
84
    {
85
        return $this->pageSize;
86
    }
87
}
88