HasSearchFilters::searchContains()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Concerns;
5
6
use Level23\Druid\SearchFilters\RegexSearchFilter;
7
use Level23\Druid\SearchFilters\ContainsSearchFilter;
8
use Level23\Druid\SearchFilters\FragmentSearchFilter;
9
use Level23\Druid\SearchFilters\SearchFilterInterface;
10
11
trait HasSearchFilters
12
{
13
    /**
14
     * @var \Level23\Druid\SearchFilters\SearchFilterInterface|null
15
     */
16
    protected ?SearchFilterInterface $searchFilter = null;
17
18
    /**
19
     * @var string[]
20
     */
21
    protected array $searchDimensions = [];
22
23
    /**
24
     * Supply the dimensions where we want to search in using a Search Query.
25
     *
26
     * @param string[] $dimensions
27
     *
28
     * @return $this
29
     */
30 1
    public function dimensions(array $dimensions): self
31
    {
32 1
        $this->searchDimensions = $dimensions;
33
34 1
        return $this;
35
    }
36
37
    /**
38
     * Only return the dimensions where the dimension contains the value specified in this search query.
39
     *
40
     * @param string $value
41
     * @param bool   $caseSensitive
42
     *
43
     * @return $this
44
     */
45 7
    public function searchContains(string $value, bool $caseSensitive = false): self
46
    {
47 7
        $this->searchFilter = new ContainsSearchFilter($value, $caseSensitive);
48
49 7
        return $this;
50
    }
51
52
    /**
53
     * Return the dimensions it contains all the values specified.
54
     *
55
     * @param array|string[] $values
56
     * @param bool           $caseSensitive
57
     *
58
     * @return $this
59
     */
60 3
    public function searchFragment(array $values, bool $caseSensitive = false): self
61
    {
62 3
        $this->searchFilter = new FragmentSearchFilter($values, $caseSensitive);
63
64 3
        return $this;
65
    }
66
67
    /**
68
     * Return the dimension if they match with the given regex pattern.
69
     *
70
     * @param string $pattern
71
     *
72
     * @return $this
73
     */
74 1
    public function searchRegex(string $pattern): self
75
    {
76 1
        $this->searchFilter = new RegexSearchFilter($pattern);
77
78 1
        return $this;
79
    }
80
}