Passed
Push — feature/optimize ( cf938e...7e8046 )
by Fu
03:43
created

ParseSearchWhereTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseSearchOrWhere() 0 7 3
A parseSearchAndWhere() 0 9 3
A parseSearchWhere() 0 7 3
1
<?php
2
3
4
namespace Modules\Core\Traits\Criteria;
5
6
trait ParseSearchWhereTrait
7
{
8
    /** @var \Illuminate\Http\Request $request */
9
    protected $request;
10
    /** @var \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder $model */
11
    protected $model;
12
    /** @var \Prettus\Repository\Contracts\RepositoryInterface $repository */
13
    protected $repository;
14
    protected $search;
15
    protected $searchData;
16
    protected $searchFields;
17
    protected $isFirstField;
18
    protected $modelForceAndWhere;
19
    protected $fieldsSearchable;
20
    protected $fields;
21
    protected $filter;
22
    protected $orderBy;
23
    protected $sortedBy;
24
    protected $with;
25
    protected $searchJoin;
26
    protected $acceptedConditions;
27
    protected $originalFields;
28
29
    use ParseSearchAndClosureTrait;
30
    use ParseSearchAndRelationClosureTrait;
31
    use ParseSearchOrClosureTrait;
32
    use ParseSearchOrRelationClosureTrait;
33
34
    protected function parseSearchWhere($value, $relation, $field, $condition)
35
    {
36
37
        if ($this->isFirstField || $this->modelForceAndWhere) {
38
            $this->parseSearchAndWhere($value, $relation, $field, $condition);
39
        } else {
40
            $this->parseSearchOrWhere($value, $relation, $field, $condition);
41
        }
42
    }
43
44
    protected function parseSearchOrWhere($value, $relation, $field, $condition)
45
    {
46
        if (!is_null($value)) {
47
            if (!is_null($relation)) {
48
                $this->parseSearchOrRelationClosure($value, $relation, $field, $condition);
49
            } else {
50
                $this->parseSearchOrClosure($value, $field, $condition);
51
            }
52
        }
53
    }
54
55
    protected function parseSearchAndWhere($value, $relation, $field, $condition)
56
    {
57
        if (!is_null($value)) {
58
            if (!is_null($relation)) {
59
                $this->parseSearchAndRelationClosure($value, $relation, $field, $condition);
60
            } else {
61
                $this->parseSearchAndClosure($value, $field, $condition);
62
            }
63
            $this->isFirstField = false;
64
        }
65
    }
66
}