Passed
Push — master ( 67e4ee...ffde43 )
by
unknown
10:56 queued 07:00
created

PageArray::getCurrentLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TheCodingMachine\TDBM;
6
7
use ArrayIterator;
8
use Traversable;
9
10
class PageArray implements PageInterface
11
{
12
    private array $items;
13
    private int $offset;
14
    private int $limit;
15
    private int $totalCount;
16
17
    /**
18
     * @param array $items
19
     */
20
    public function __construct(array $items, int $offset, int $limit, int $totalCount)
21
    {
22
        $this->items = $items;
23
        $this->offset = $offset;
24
        $this->limit = $limit;
25
        $this->totalCount = $totalCount;
26
    }
27
28
    public function count(): int
29
    {
30
        return count($this->items);
31
    }
32
33
    public function totalCount(): int
34
    {
35
        return $this->totalCount;
36
    }
37
38
    public function getCurrentOffset(): int
39
    {
40
        return $this->offset;
41
    }
42
43
    public function getCurrentPage(): int
44
    {
45
        return (int) floor($this->offset / $this->limit) + 1;
46
    }
47
48
    public function getCurrentLimit(): int
49
    {
50
        return $this->limit;
51
    }
52
53
    public function getIterator(): Traversable
54
    {
55
        return new ArrayIterator($this->items);
56
    }
57
}
58