Issues (40)

src/Arrays/ArrayPage.php (1 issue)

1
<?php
2
3
namespace Zenstruck\Porpaginas\Arrays;
4
5
use Zenstruck\Porpaginas\Page;
6
7
final class ArrayPage implements Page
8
{
9
    private array $slice;
10
    private int $offset;
11
    private int $limit;
12
    private int $totalCount;
13
14 22
    public function __construct(array $slice, int $offset, int $limit, int $totalCount)
15
    {
16 22
        $this->slice = $slice;
17 22
        $this->offset = $offset;
18 22
        $this->limit = $limit;
19 22
        $this->totalCount = $totalCount;
20 22
    }
21
22 4
    public function currentOffset(): int
23
    {
24 4
        return $this->offset;
25
    }
26
27 4
    public function currentPage(): int
28
    {
29 4
        return \floor($this->offset / $this->limit) + 1;
0 ignored issues
show
Bug Best Practice introduced by
The expression return floor($this->offset / $this->limit) + 1 returns the type double which is incompatible with the type-hinted return integer.
Loading history...
30
    }
31
32 4
    public function currentLimit(): int
33
    {
34 4
        return $this->limit;
35
    }
36
37 16
    public function count(): int
38
    {
39 16
        return \count($this->slice);
40
    }
41
42 2
    public function totalCount(): int
43
    {
44 2
        return $this->totalCount;
45
    }
46
47 18
    public function getIterator(): \Traversable
48
    {
49 18
        return new \ArrayIterator($this->slice);
50
    }
51
}
52