FilterScope   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filter() 0 11 3
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