Completed
Push — master ( 80b847...ba65ab )
by Zing
10:58
created

FiltersPartial::withPropertyConstraint()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 2
nop 3
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Filters;
6
7
use Illuminate\Database\Eloquent\Builder;
8
9
class FiltersPartial extends FiltersExact
10
{
11 5
    protected function withPropertyConstraint(Builder $query, $value, $property)
12
    {
13 5
        if (is_array($value)) {
14 3
            return $query->where(
15
                function ($query) use ($value, $property): void {
16 3
                    foreach ($value as $partialValue) {
17 3
                        $query->orWhere($property, 'like', "%{$partialValue}%");
18
                    }
19 3
                }
20
            );
21
        }
22
23 2
        return $query->where($property, 'like', "%{$value}%");
24
    }
25
}
26