BaseDataProvider::__construct()   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 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace ChurakovMike\EasyGrid\DataProviders;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Http\Request;
7
8
/**
9
 * Class BaseDataProvider.
10
 * @package ChurakovMike\EasyGrid\DataProviders
11
 *
12
 * @property Builder $query
13
 */
14
abstract class BaseDataProvider
15
{
16
    /**
17
     * Copy of query.
18
     *
19
     * @var Builder $query
20
     */
21
    protected $query;
22
23
    /**
24
     * EloquentDataProvider constructor.
25
     * @param Builder $query
26
     */
27
    public function __construct(Builder $query)
28
    {
29
        $this->query = clone $query;
30
    }
31
32
    /**
33
     * @param Request $request
34
     */
35
    public function get(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

35
    public function get(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
    }
38
39
    /**
40
     * Get rows count.
41
     *
42
     * @return int
43
     */
44
    public function getCount(): int
45
    {
46
        return $this->query->count();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->query->count() could return the type Illuminate\Database\Eloquent\Builder which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
47
    }
48
49
    /**
50
     * Apply query sort.
51
     *
52
     * @param string $column
53
     * @param string $direction
54
     */
55
    public function sort(string $column, string $direction): void
56
    {
57
        $this->query->orderBy($column, $direction);
58
    }
59
}
60