WithSearchQueryCriterion   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A apply() 0 10 2
1
<?php
2
3
namespace Napp\Core\Dbal\Criteria;
4
5
class WithSearchQueryCriterion implements CriterionInterface
6
{
7
    /** @var string */
8
    protected $searchQuery;
9
10
    /** @var array */
11
    protected $field;
12
13
    /**
14
     * WithSearchQueryCriterion constructor.
15
     *
16
     * @param string      $searchQuery
17
     * @param string|null $field
18
     */
19
    public function __construct(string $searchQuery, string $field = null)
20
    {
21
        $this->searchQuery = $searchQuery;
22
        $this->field = $field;
0 ignored issues
show
Documentation Bug introduced by
It seems like $field of type null or string is incompatible with the declared type array of property $field.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
    }
24
25
    /**
26
     * @param \Illuminate\Database\Eloquent\Builder $query
27
     *
28
     * @return \Illuminate\Database\Eloquent\Builder
29
     */
30
    public function apply($query)
31
    {
32
        if (null === $this->field) {
33
            return $query;
34
        }
35
36
        $query->getQuery()->where($this->field, 'LIKE', '%'.$this->searchQuery.'%');
37
38
        return $query;
39
    }
40
}
41