Passed
Push — master ( ac21bd...36df2b )
by noitran
03:42
created

BuildsQueries   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 53
c 0
b 0
f 0
ccs 0
cts 12
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A with() 0 5 1
A withCount() 0 5 1
A withTrashed() 0 5 1
A orderBy() 0 5 1
1
<?php
2
3
namespace Noitran\Repositories\Repositories\Concerns;
4
5
/**
6
 * Trait BuildsQueries
7
 */
8
trait BuildsQueries
9
{
10
    /**
11
     * Eager load relations
12
     *
13
     * @param array|string $relations
14
     *
15
     * @return $this
16
     */
17
    public function with($relations): self
18
    {
19
        $this->model = $this->model->with($relations);
0 ignored issues
show
Bug Best Practice introduced by
The property model does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
21
        return $this;
22
    }
23
24
    /**
25
     * @return $this
26
     */
27
    public function withTrashed(): self
28
    {
29
        $this->model = $this->model->withTrashed();
0 ignored issues
show
Bug Best Practice introduced by
The property model does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
31
        return $this;
32
    }
33
34
    /**
35
     * Add sub-select queries to count the relations.
36
     *
37
     * @param mixed $relations
38
     *
39
     * @return $this
40
     */
41
    public function withCount($relations): self
42
    {
43
        $this->model = $this->model->withCount($relations);
0 ignored issues
show
Bug Best Practice introduced by
The property model does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
44
45
        return $this;
46
    }
47
48
    /**
49
     * Add an "order by" clause to the query.
50
     *
51
     * @param $column
52
     * @param string $direction
53
     *
54
     * @return BuildsQueries
55
     */
56
    public function orderBy($column, $direction = 'asc'): self
57
    {
58
        $this->model = $this->model->orderBy($column, $direction);
0 ignored issues
show
Bug Best Practice introduced by
The property model does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
59
60
        return $this;
61
    }
62
}
63