Completed
Push — master ( 9d2442...b1f272 )
by Denis
01:49
created

EloquentDataProvider::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Woo\GridView\DataProviders;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
class EloquentDataProvider implements DataProviderInterface
8
{
9
    protected $query;
10
11
    /**
12
     * EloquentDataProvider constructor.
13
     * @param Builder $query
14
     */
15
    public function __construct(Builder $query)
16
    {
17
        $this->query = $query;
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function getCount(): int
24
    {
25
        return $this->query->count();
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function getTotalPages(int $perPage): int
32
    {
33
        return ceil($this->getCount() / $perPage);
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function getData(int $page, int $perPage)
40
    {
41
        return (clone $this->query)->paginate($perPage, ['*'], 'page', $page);
42
    }
43
}