Completed
Pull Request — master (#15)
by Daniel
02:00
created

Paginator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPageSize() 0 4 1
A getCurrentPage() 0 4 1
A getNumberOfRecords() 0 4 1
A getLastPage() 0 4 1
A isLastPage() 0 4 1
A getLinkParams() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid;
6
7
class Paginator
8
{
9
    private $options;
10
    private $numberOfRecords;
11
12
    public function __construct(GridContext $options, int $numberOfRecordsOnPage, int $numberOfRecords = null)
13
    {
14
        $this->options = $options;
15
        $this->numberOfRecords = $numberOfRecords;
16
        $this->numberOfRecordsOnPage = $numberOfRecordsOnPage;
0 ignored issues
show
Bug introduced by
The property numberOfRecordsOnPage does not seem to exist. Did you mean numberOfRecords?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
17
    }
18
19
    public function getPageSize(): int
20
    {
21
        return $this->options->getPageSize();
22
    }
23
24
    public function getCurrentPage(): int
25
    {
26
        return $this->options->getCurrentPage();
27
    }
28
29
    public function getNumberOfRecords()
30
    {
31
        return $this->numberOfRecords;
32
    }
33
34
    public function getLastPage(): int
35
    {
36
        return (int) ceil($this->getNumberOfRecords() / $this->getPageSize());
37
    }
38
39
    public function isLastPage(): bool
40
    {
41
        return $this->numberOfRecordsOnPage < $this->getPageSize();
0 ignored issues
show
Bug introduced by
The property numberOfRecordsOnPage does not seem to exist. Did you mean numberOfRecords?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
42
    }
43
44
    public function getLinkParams($page = null)
45
    {
46
        return array_merge($this->options->getOptions(), [
47
            'current_page' => $page ?: $this->options->getCurrentPage(),
48
        ]);
49
    }
50
}
51