Passed
Push — master ( 6028dd...89a59a )
by Vitaliy
02:15
created

FilterHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPriority() 4 4 1
A apply() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Nayjest\Querying\Handler\Illuminate;
4
5
use Nayjest\Querying\Handler\AbstractHandler;
6
use Nayjest\Querying\Handler\DatabaseFilterHandlerTrait;
7
use Nayjest\Querying\Handler\Priority;
8
use Nayjest\Querying\Operation\FilterOperation;
9
use Illuminate\Database\Eloquent\Builder;
10
11
/**
12
 * FilterOperation processing for DoctrineDataProvider.
13
 *
14
 * @see FilterOperation
15
 */
16 View Code Duplication
class FilterHandler extends AbstractHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    use DatabaseFilterHandlerTrait;
19
20 1
    public function getPriority()
21
    {
22 1
        return Priority::MAIN;
23
    }
24
25
    /**
26
     * Applies operation to data source and returns modified data source.
27
     *
28
     * @param Builder $src
29
     * @return Builder
30
     */
31 1
    public function apply($src)
32
    {
33
        /** @var FilterOperation $operation */
34 1
        $operation = $this->operation;
35 1
        list($operator, $value) = $this->getOperatorAndValue();
36 1
        $fieldName = $operation->getField();
37 1
        $src->where($fieldName, $operator, $value);
38 1
        return $src;
39
    }
40
}
41