Passed
Push β€” feature/optimize ( 219eef...0e0305 )
by Fu
03:34
created

RequestCriteria::parserFieldsSearch()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 28
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
rs 8.8333
c 0
b 0
f 0
cc 7
nc 3
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: guoliang
5
 * Date: 2019/3/11
6
 * Time: 上午10:11
7
 */
8
9
namespace Modules\Core\Criteria;
10
11
12
use Illuminate\Http\Request;
13
use Modules\Core\Traits\Criteria\{
14
    ParserFilterTrait,
15
    ParserOrderByTrait,
16
    ParserSearchableTrait,
17
    ParserWithTrait
18
};
19
use Prettus\Repository\Contracts\{
20
    CriteriaInterface,
21
    RepositoryInterface
22
};
23
24
class RequestCriteria implements CriteriaInterface
25
{
26
    protected $request;
27
    protected $model;
28
    protected $repository;
29
    protected $search;
30
    protected $searchData;
31
    protected $searchFields;
32
    protected $isFirstField = true;
33
    protected $modelForceAndWhere;
34
    protected $fieldsSearchable;
35
    protected $fields;
36
    protected $filter;
37
    protected $orderBy;
38
    protected $sortedBy;
39
    protected $with;
40
    protected $searchJoin;
41
    protected $acceptedConditions;
42
    protected $originalFields;
43
44
    use ParserSearchableTrait;
45
    use ParserOrderByTrait;
46
    use ParserFilterTrait;
47
    use ParserWithTrait;
48
49
    public function __construct(Request $request)
50
    {
51
        $this->request = $request;
52
    }
53
54
    /**
55
     * @param $model
56
     * @param \Prettus\Repository\Contracts\RepositoryInterface $repository
57
     * @return mixed
58
     * @throws \Exception
59
     */
60
    public function apply($model, RepositoryInterface $repository)
61
    {
62
        $this->model = $model;
63
        $this->repository = $repository;
64
65
        $this->parserSearchable();
66
        $this->parserOrderBy();
67
        $this->parserFilter();
68
        $this->parserWith();
69
70
        return $this->model;
71
    }
72
}
73