PaginatedCollection   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 63
rs 10
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getPageStart() 0 7 2
A getPageEnd() 0 7 2
A getTotalPages() 0 7 2
A getTotalCount() 0 3 1
A __construct() 0 6 1
A getCurrentPage() 0 3 1
A getPerPage() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Collection;
5
6
class PaginatedCollection extends Collection
7
{
8
    protected $totalCount;
9
    protected $perPage;
10
    protected $currentPage;
11
12
    public function __construct(array $elements, int $totalCount, int $perPage, int $currentPage)
13
    {
14
        parent::__construct($elements);
15
        $this->totalCount  = $totalCount;
16
        $this->perPage     = $perPage;
17
        $this->currentPage = $currentPage;
18
    }
19
20
    /**
21
     * @return mixed
22
     */
23
    public function getTotalCount()
24
    {
25
        return $this->totalCount;
26
    }
27
28
    /**
29
     * @return mixed
30
     */
31
    public function getPerPage()
32
    {
33
        return $this->perPage;
34
    }
35
36
    /**
37
     * @return mixed
38
     */
39
    public function getCurrentPage()
40
    {
41
        return $this->currentPage;
42
    }
43
44
    public function getTotalPages()
45
    {
46
        if ($this->perPage < 1) {
47
            return 0;
48
        }
49
50
        return ceil($this->totalCount / $this->perPage);
51
    }
52
53
    public function getPageStart()
54
    {
55
        if ($this->totalCount < 1) {
56
            return 0;
57
        }
58
59
        return 1 + $this->perPage * ($this->currentPage - 1);
60
    }
61
62
    public function getPageEnd()
63
    {
64
        if ($this->totalCount < 1) {
65
            return 0;
66
        }
67
68
        return $this->getPageStart() + $this->count() - 1;
69
    }
70
}
71