KendoScope::kendoRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Zgabievi\KendoGridState\Scopes;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Scope;
7
use Illuminate\Database\Eloquent\Builder;
8
use Zgabievi\KendoGridState\Filters\Skip;
9
use Zgabievi\KendoGridState\Filters\Sort;
10
use Zgabievi\KendoGridState\Filters\Take;
11
use Zgabievi\KendoGridState\Filters\Group;
12
use Zgabievi\KendoGridState\Filters\State;
13
use Zgabievi\KendoGridState\Filters\Filter;
14
15
class KendoScope implements Scope
16
{
17
    /**
18
     * @var array
19
     */
20
    public static $filters = [
21
        'filter' => Filter::class,
22
        'group' => Group::class,
23
        'skip' => Skip::class,
24
        'sort' => Sort::class,
25
        'take' => Take::class,
26
    ];
27
28
    /**
29
     * Apply the scope to a given Eloquent query builder.
30
     *
31
     * @param Builder $builder
32
     * @param Model $model
33
     * @return \Illuminate\Database\Query\Builder|Builder
34
     */
35
    public function apply(Builder $builder, Model $model)
36
    {
37
        return (new State($this->kendoRequest()))->filter($builder);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Zgabievi\Kend...st())->filter($builder) returns the type Illuminate\Database\Eloquent\Builder which is incompatible with the return type mandated by Illuminate\Database\Eloquent\Scope::apply() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    protected function kendoRequest()
44
    {
45
        return array_filter(
46
            request()->only(
47
                array_keys(self::$filters)
48
            )
49
        );
50
    }
51
}
52