Completed
Push — master ( 5649ba...c37d73 )
by recca
03:09
created

EloquentBuildsQueries   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A whereKey() 0 6 1
A whereKeyNot() 0 6 1
A with() 0 6 1
A without() 0 6 1
A setQuery() 0 6 1
A setModel() 0 6 1
1
<?php
2
3
namespace Recca0120\Repository\Concerns;
4
5
use Recca0120\Repository\Method;
6
use Illuminate\Database\Eloquent\Model;
7
8
trait EloquentBuildsQueries
9
{
10
    /**
11
     * Add a where clause on the primary key to the query.
12
     *
13
     * @param  mixed  $id
14
     * @return $this
15
     */
16
    public function whereKey($id)
17
    {
18
        $this->methods[] = new Method(__FUNCTION__, [$id]);
0 ignored issues
show
Bug introduced by
The property methods does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
20
        return $this;
21
    }
22
23
    /**
24
     * Add a where clause on the primary key to the query.
25
     *
26
     * @param  mixed  $id
27
     * @return $this
28
     */
29
    public function whereKeyNot($id)
30
    {
31
        $this->methods[] = new Method(__FUNCTION__, [$id]);
32
33
        return $this;
34
    }
35
36
    /**
37
     * Set the relationships that should be eager loaded.
38
     *
39
     * @param  mixed  $relations
40
     * @return $this
41
     */
42
    public function with($relations)
43
    {
44
        $this->methods[] = new Method(__FUNCTION__, [$relations]);
45
46
        return $this;
47
    }
48
49
    /**
50
     * Prevent the specified relations from being eager loaded.
51
     *
52
     * @param  mixed  $relations
53
     * @return $this
54
     */
55
    public function without($relations)
56
    {
57
        $this->methods[] = new Method(__FUNCTION__, [$relations]);
58
59
        return $this;
60
    }
61
62
    /**
63
     * Set the underlying query builder instance.
64
     *
65
     * @param  \Illuminate\Database\Query\Builder  $query
66
     * @return $this
67
     */
68
    public function setQuery($query)
69
    {
70
        $this->methods[] = new Method(__FUNCTION__, [$query]);
71
72
        return $this;
73
    }
74
75
    /**
76
     * Set a model instance for the model being queried.
77
     *
78
     * @param  \Illuminate\Database\Eloquent\Model  $model
79
     * @return $this
80
     */
81
    public function setModel(Model $model)
82
    {
83
        $this->methods[] = new Method(__FUNCTION__, [$model]);
84
85
        return $this;
86
    }
87
}
88