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

Paginator::getLinkParams()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 1
nop 1
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(GridOptions $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