BuildsQueries   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 53
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
declare(strict_types=1);
4
5
namespace Noitran\Repositories\Repositories\Concerns;
6
7
/**
8
 * Trait BuildsQueries.
9
 */
10
trait BuildsQueries
11
{
12
    /**
13
     * Eager load relations.
14
     *
15
     * @param array|string $relations
16
     *
17
     * @return $this
18
     */
19
    public function with($relations): self
20
    {
21
        $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...
22
23
        return $this;
24
    }
25
26
    /**
27
     * @return $this
28
     */
29
    public function withTrashed(): self
30
    {
31
        $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...
32
33
        return $this;
34
    }
35
36
    /**
37
     * Add sub-select queries to count the relations.
38
     *
39
     * @param mixed $relations
40
     *
41
     * @return $this
42
     */
43
    public function withCount($relations): self
44
    {
45
        $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...
46
47
        return $this;
48
    }
49
50
    /**
51
     * Add an "order by" clause to the query.
52
     *
53
     * @param $column
54
     * @param string $direction
55
     *
56
     * @return BuildsQueries
57
     */
58
    public function orderBy($column, $direction = 'asc'): self
59
    {
60
        $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...
61
62
        return $this;
63
    }
64
}
65