Passed
Push — master ( dc3688...f2f34e )
by Pavel
02:13
created

StringFilterParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyFilter() 0 9 3
A __construct() 0 4 1
1
<?php namespace Pz\Doctrine\Rest\QueryParser;
2
3
use Doctrine\Common\Collections\Criteria;
4
use Pz\Doctrine\Rest\Contracts\RestRequestContract;
5
6
class StringFilterParser extends FilterParserAbstract
7
{
8
    const PARAM_PREFIX = '';
9
10
    /**
11
     * @var string|bool
12
     */
13
    protected $property;
14
15
    /**
16
     * StringParser constructor.
17
     *
18
     * @param RestRequestContract $request
19
     * @param string              $property Property name that will be filtered by query.
20
     */
21 8
    public function __construct(RestRequestContract $request, $property)
22
    {
23 8
        parent::__construct($request);
24 8
        $this->property = $property;
25 8
    }
26
27
    /**
28
     * Assign LIKE operator on property if query is string.
29
     *
30
     * @param Criteria $criteria
31
     * @param          $filter
32
     *
33
     * @return Criteria
34
     */
35 8
    public function applyFilter(Criteria $criteria, $filter)
36
    {
37 8
        if (is_string($filter) && is_string($this->property)) {
38 2
            $criteria->andWhere(
39 2
                $criteria->expr()->contains($this->property, $filter)
40
            );
41
        }
42
43 8
        return $criteria;
44
    }
45
}
46