FilterScope::filter()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 3
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 9.9
c 0
b 0
f 0
1
<?php
2
namespace NwLaravel\Repositories\Criterias\Filters;
3
4
class FilterScope implements FilterInterface
5
{
6
    /**
7
     * @var Model
8
     */
9
    protected $model;
10
11
    /**
12
     * Construct
13
     *
14
     * @param Model $model
15
     */
16 14
    public function __construct($model)
17
    {
18 14
        $this->model = $model;
19 14
    }
20
21
    /**
22
     * Filter
23
     *
24
     * @param Query\Builder $query
25
     * @param int|string    $key
26
     * @param mixed         $value
27
     *
28
     * @return boolean
29
     */
30 14
    public function filter($query, $key, $value)
31
    {
32 14
        $methodScope = 'scope' . studly_case($key);
0 ignored issues
show
Deprecated Code introduced by
The function studly_case() has been deprecated with message: Str::studly() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
33 14
        if (is_object($this->model) && method_exists($this->model, $methodScope)) {
34 2
            $methodName = camel_case($key);
0 ignored issues
show
Deprecated Code introduced by
The function camel_case() has been deprecated with message: Str::camel() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
35 2
            $query = $query->{$methodName}($value);
0 ignored issues
show
Unused Code introduced by
$query is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36 2
            return true;
37
        }
38
39 13
        return false;
40
    }
41
}
42