Test Setup Failed
Push — master ( 3ef048...5fd193 )
by Vitaliy
02:08
created

DatabaseFilterHandlerTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 27
rs 10

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
    protected function getOperatorAndValue()
12
    {
13
        /** @var  FilterOperation $operation */
14
        $operation = $this->getOperation();
15
        $operator = $operation->getOperator();
16
        $value = $operation->getValue();
17
        switch ($operator) {
18
            case FilterOperation::OPERATOR_STR_STARTS_WITH:
19
                $operator = FilterOperation::OPERATOR_LIKE;
20
                $value .= '%';
21
                break;
22
            case FilterOperation::OPERATOR_STR_ENDS_WITH:
23
                $operator = FilterOperation::OPERATOR_LIKE;
24
                $value = '%' . $value;
25
                break;
26
            case FilterOperation::OPERATOR_STR_CONTAINS:
27
                $operator = FilterOperation::OPERATOR_LIKE;
28
                $value = '%' . $value . '%';
29
                break;
30
        }
31
        return [$operator, $value];
32
    }
33
}
34