ParseSearchDataTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseSearchData() 0 18 4
1
<?php
2
3
namespace Modules\Core\Traits\Criteria;
4
5
use Exception;
6
7
trait ParseSearchDataTrait
8
{
9
    /** @var \Illuminate\Http\Request $request */
10
    protected $request;
11
    /** @var \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder $model */
12
    protected $model;
13
    /** @var \Prettus\Repository\Contracts\RepositoryInterface $repository */
14
    protected $repository;
15
    protected $search;
16
    protected $searchData;
17
    protected $searchFields;
18
    protected $isFirstField;
19
    protected $modelForceAndWhere;
20
    protected $fieldsSearchable;
21
    protected $fields;
22
    protected $filter;
23
    protected $orderBy;
24
    protected $sortedBy;
25
    protected $with;
26
    protected $searchJoin;
27
    protected $acceptedConditions;
28
    protected $originalFields;
29
    protected $searchClosures;
30
31
    protected function parseSearchData()
32
    {
33
        $searchData = [];
34
35
        if (stripos($this->search, ':')) {
36
            $fields = explode(';', $this->search);
37
38
            foreach ($fields as $row) {
39
                try {
40
                    list($field, $value) = explode(':', $row);
41
                    $searchData[$field] = $value;
42
                } catch (Exception $e) {
43
                    //Surround offset error
44
                }
45
            }
46
        }
47
48
        $this->searchData = $searchData;
49
    }
50
}
51