SearchFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 52
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 15 2
A getQueryCondition() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of slick/mvc package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mvc\Service\Entity\QueryFilter;
11
12
use Slick\Common\Base;
13
use Slick\Mvc\Service\Entity\QueryFilterInterface;
14
use Slick\Orm\Repository\QueryObject\QueryObjectInterface;
15
16
/**
17
 * Search Filter
18
 * 
19
 * @package Slick\Mvc\Service\Entity\QueryFilter
20
 * @author  Filipe Silva <[email protected]>
21
 * 
22
 * @property string   $pattern
23
 * @property string[] $fields
24
 */
25
class SearchFilter extends Base implements QueryFilterInterface
26
{
27
28
    /**
29
     * @readwrite
30
     * @var string
31
     */
32
    protected $pattern;
33
34
    /**
35
     * @readwrite
36
     * @var string[]
37
     */
38
    protected $fields = [];
39
    
40
    /**
41
     * Applies the filter to the provided query
42
     *
43
     * @param QueryObjectInterface $query
44
     *
45
     * @return $this|self|QueryFilterInterface
46
     */
47 4
    public function apply(QueryObjectInterface $query)
48
    {
49 4
        if (empty($this->fields)) {
50 2
            return $this;
51
        }
52
        
53 2
        $query->where(
54
            [
0 ignored issues
show
Documentation introduced by
array($this->getQueryCon... "%{$this->pattern}%")) is of type array<string,array<string,?>>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55 2
                $this->getQueryCondition() => [
56 2
                    ':pattern' => "%{$this->pattern}%"
57 1
                ]
58 1
            ]
59 1
        );
60 2
        return $this;
61
    }
62
63
    /**
64
     * Gets the query condition for provided fields
65
     * 
66
     * @return string
67
     */
68 2
    protected function getQueryCondition()
69
    {
70 2
        $parts = [];
71 2
        foreach ($this->fields as $field) {
72 2
            $parts[] = "{$field} LIKE :pattern";
73 1
        }
74 2
        return implode(' AND ', $parts);
75
    }
76
}