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

FilterHandler::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
nc 1
cc 1
eloc 6
nop 1
crap 1
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