DatabaseFilterHandlerTrait::getOperatorAndValue()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.3739

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 8
cts 17
cp 0.4706
rs 8.9197
c 0
b 0
f 0
nc 4
cc 4
eloc 18
nop 0
crap 6.3739
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