Collection::recordCount()   A
last analyzed

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
    protected array $pagination = [];
10
11
    /**
12
     * Current page that the collection holds
13
     */
14
    public function page(): ?int
15
    {
16
        return $this->pagination['page'] ?? null;
17
    }
18
19
    /**
20
     * Number of avaliable pages
21
     */
22
    public function pages(): ?int
23
    {
24
        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...
25
    }
26
27
    /**
28
     * Records per page
29
     */
30
    public function pageSize(): ?int
31
    {
32
        return $this->pagination['pageSize'] ?? null;
33
    }
34
35
    /**
36
     * Count of records avaliable in the the
37
     */
38
    public function recordCount(): ?int
39
    {
40
        return $this->pagination['count'] ?? null;
41
    }
42
43
    /**
44
     * Set pagination
45
     */
46
    public function setPagination(?int $count = null, ?int $page = null, ?int $pageSize = null): self
47
    {
48
        $this->pagination = array_merge($this->pagination, compact('count', 'page', 'pageSize'));
49
50
        return $this;
51
    }
52
}
53