Test Setup Failed
Push — develop ( 13e851...151a72 )
by Jimmy
14:05
created

Collection::pages()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spinen\Halo\Support;
4
5
use Illuminate\Support\Collection as BaseCollection;
6
7
class Collection extends BaseCollection
8
{
9
    /**
10
     *
11
     * @var array
12
     */
13
    protected array $pagination = [];
14
15
    /**
16
     * Current page that the collection holds
17
     */
18
    public function page(): ?int
19
    {
20
        return $this->pagination['page'] ?? null;
21
    }
22
23
    /**
24
     * Number of avaliable pages
25
     */
26
    public function pages(): ?int
27
    {
28
        return ceil($this->recordCount() / $this->pageSize());
0 ignored issues
show
Bug Best Practice introduced by
The expression return ceil($this->recor...() / $this->pageSize()) returns the type double which is incompatible with the type-hinted return integer|null.
Loading history...
29
    }
30
31
    /**
32
     * Records per page
33
     */
34
    public function pageSize(): ?int
35
    {
36
        return $this->pagination['pageSize'] ?? null;
37
    }
38
39
    /**
40
     * Count of records avaliable in the the
41
     */
42
    public function recordCount(): ?int
43
    {
44
        return $this->pagination['count'] ?? null;
45
    }
46
47
    /**
48
     * Set pagination
49
     */
50
    public function setPagination(?int $count = null, ?int $page = null, ?int $pageSize = null): self
51
    {
52
        $this->pagination = array_merge($this->pagination, compact('count', 'page', 'pageSize'));
53
54
        return $this;
55
    }
56
}
57