EloquentBuildsQueries::setQuery()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\Repository\Concerns;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Recca0120\Repository\Method;
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 1
    public function whereKey($id)
17
    {
18 1
        $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 1
        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 1
    public function whereKeyNot($id)
30
    {
31 1
        $this->methods[] = new Method(__FUNCTION__, [$id]);
32
33 1
        return $this;
34
    }
35
36
    /**
37
     * Set the relationships that should be eager loaded.
38
     *
39
     * @param  mixed  $relations
40
     * @return $this
41
     */
42 1
    public function with($relations)
0 ignored issues
show
Unused Code introduced by
The parameter $relations is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44 1
        $this->methods[] = new Method(__FUNCTION__, func_get_args());
45
46 1
        return $this;
47
    }
48
49
    /**
50
     * Prevent the specified relations from being eager loaded.
51
     *
52
     * @param  mixed  $relations
53
     * @return $this
54
     */
55 1
    public function without($relations)
0 ignored issues
show
Unused Code introduced by
The parameter $relations is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57 1
        $this->methods[] = new Method(__FUNCTION__, func_get_args());
58
59 1
        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 1
    public function setQuery($query)
69
    {
70 1
        $this->methods[] = new Method(__FUNCTION__, [$query]);
71
72 1
        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 1
    public function setModel(Model $model)
82
    {
83 1
        $this->methods[] = new Method(__FUNCTION__, [$model]);
84
85 1
        return $this;
86
    }
87
88
    /**
89
     * Begin querying the model on the write connection.
90
     *
91
     * @return \Illuminate\Database\Query\Builder
92
     */
93 1
    public function onWriteConnection()
94
    {
95 1
        return $this->useWritePdo();
0 ignored issues
show
Bug introduced by
It seems like useWritePdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
96
    }
97
}
98