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

DatabaseFilterHandlerTrait::getOperatorAndValue()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 8.9197
cc 4
eloc 18
nc 4
nop 0
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