DatabaseFilterHandlerTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 47.06%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
getOperation() 0 1 ?
B getOperatorAndValue() 0 22 4
1
<?php
2
3
namespace Nayjest\Querying\Handler;
4
5
use Nayjest\Querying\Operation\FilterOperation;
6
7
trait DatabaseFilterHandlerTrait
8
{
9
    abstract protected function getOperation();
10
11 2
    protected function getOperatorAndValue()
12
    {
13
        /** @var  FilterOperation $operation */
14 2
        $operation = $this->getOperation();
15 2
        $operator = $operation->getOperator();
16 2
        $value = $operation->getValue();
17
        switch ($operator) {
18 2
            case FilterOperation::OPERATOR_STR_STARTS_WITH:
19
                $operator = FilterOperation::OPERATOR_LIKE;
20
                $value .= '%';
21
                break;
22 2
            case FilterOperation::OPERATOR_STR_ENDS_WITH:
23
                $operator = FilterOperation::OPERATOR_LIKE;
24
                $value = '%' . $value;
25
                break;
26 2
            case FilterOperation::OPERATOR_STR_CONTAINS:
27
                $operator = FilterOperation::OPERATOR_LIKE;
28
                $value = '%' . $value . '%';
29
                break;
30
        }
31 2
        return [$operator, $value];
32
    }
33
}
34