Passed
Push — master ( 0d1e3a...a8104a )
by Jonas
11:45
created

HasEagerLimitRelationships::newBelongsToMany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 11
ccs 2
cts 2
cp 1
crap 1
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Staudenmeir\EloquentEagerLimit\Traits;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Staudenmeir\EloquentEagerLimit\Relations\BelongsToMany;
8
use Staudenmeir\EloquentEagerLimit\Relations\HasMany;
9
use Staudenmeir\EloquentEagerLimit\Relations\HasManyThrough;
10
use Staudenmeir\EloquentEagerLimit\Relations\HasOne;
11
use Staudenmeir\EloquentEagerLimit\Relations\HasOneThrough;
12
use Staudenmeir\EloquentEagerLimit\Relations\MorphMany;
13
use Staudenmeir\EloquentEagerLimit\Relations\MorphOne;
14
use Staudenmeir\EloquentEagerLimit\Relations\MorphToMany;
15
16
trait HasEagerLimitRelationships
17
{
18
    /**
19
     * Instantiate a new HasOne relationship.
20
     *
21
     * @param \Illuminate\Database\Eloquent\Builder $query
22
     * @param \Illuminate\Database\Eloquent\Model $parent
23
     * @param string $foreignKey
24
     * @param string $localKey
25
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
26
     */
27 24
    protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey)
28
    {
29 24
        return new HasOne($query, $parent, $foreignKey, $localKey);
30
    }
31
32
    /**
33
     * Instantiate a new HasOneThrough relationship.
34
     *
35
     * @param \Illuminate\Database\Eloquent\Builder $query
36
     * @param \Illuminate\Database\Eloquent\Model $farParent
37
     * @param \Illuminate\Database\Eloquent\Model $throughParent
38
     * @param string $firstKey
39
     * @param string $secondKey
40
     * @param string $localKey
41
     * @param string $secondLocalKey
42
     * @return \Illuminate\Database\Eloquent\Relations\HasOneThrough
43
     */
44 16
    protected function newHasOneThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey)
45
    {
46 16
        return new HasOneThrough($query, $farParent, $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey);
47
    }
48
49
    /**
50
     * Instantiate a new MorphOne relationship.
51
     *
52
     * @param \Illuminate\Database\Eloquent\Builder $query
53
     * @param \Illuminate\Database\Eloquent\Model $parent
54
     * @param string $type
55
     * @param string $id
56
     * @param string $localKey
57
     * @return \Illuminate\Database\Eloquent\Relations\MorphOne
58
     */
59 16
    protected function newMorphOne(Builder $query, Model $parent, $type, $id, $localKey)
60
    {
61 16
        return new MorphOne($query, $parent, $type, $id, $localKey);
62
    }
63
64
    /**
65
     * Instantiate a new HasMany relationship.
66
     *
67
     * @param \Illuminate\Database\Eloquent\Builder $query
68
     * @param \Illuminate\Database\Eloquent\Model $parent
69
     * @param string $foreignKey
70
     * @param string $localKey
71
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
72
     */
73 16
    protected function newHasMany(Builder $query, Model $parent, $foreignKey, $localKey)
74
    {
75 16
        return new HasMany($query, $parent, $foreignKey, $localKey);
76
    }
77
78
    /**
79
     * Instantiate a new HasManyThrough relationship.
80
     *
81
     * @param \Illuminate\Database\Eloquent\Builder $query
82
     * @param \Illuminate\Database\Eloquent\Model $farParent
83
     * @param \Illuminate\Database\Eloquent\Model $throughParent
84
     * @param string $firstKey
85
     * @param string $secondKey
86
     * @param string $localKey
87
     * @param string $secondLocalKey
88
     * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
89
     */
90 16
    protected function newHasManyThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey)
91
    {
92 16
        return new HasManyThrough($query, $farParent, $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey);
93
    }
94
95
    /**
96
     * Instantiate a new MorphMany relationship.
97
     *
98
     * @param \Illuminate\Database\Eloquent\Builder $query
99
     * @param \Illuminate\Database\Eloquent\Model $parent
100
     * @param string $type
101
     * @param string $id
102
     * @param string $localKey
103
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
104
     */
105 16
    protected function newMorphMany(Builder $query, Model $parent, $type, $id, $localKey)
106
    {
107 16
        return new MorphMany($query, $parent, $type, $id, $localKey);
108
    }
109
110
    /**
111
     * Instantiate a new BelongsToMany relationship.
112
     *
113
     * @param \Illuminate\Database\Eloquent\Builder $query
114
     * @param \Illuminate\Database\Eloquent\Model $parent
115
     * @param string $table
116
     * @param string $foreignPivotKey
117
     * @param string $relatedPivotKey
118
     * @param string $parentKey
119
     * @param string $relatedKey
120
     * @param string $relationName
121
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
122
     */
123 16
    protected function newBelongsToMany(
124
        Builder $query,
125
        Model $parent,
126
        $table,
127
        $foreignPivotKey,
128
        $relatedPivotKey,
129
        $parentKey,
130
        $relatedKey,
131
        $relationName = null
132
    ) {
133 16
        return new BelongsToMany($query, $parent, $table, $foreignPivotKey, $relatedPivotKey, $parentKey, $relatedKey, $relationName);
134
    }
135
136
    /**
137
     * Instantiate a new MorphToMany relationship.
138
     *
139
     * @param \Illuminate\Database\Eloquent\Builder $query
140
     * @param \Illuminate\Database\Eloquent\Model $parent
141
     * @param string $name
142
     * @param string $table
143
     * @param string $foreignPivotKey
144
     * @param string $relatedPivotKey
145
     * @param string $parentKey
146
     * @param string $relatedKey
147
     * @param string $relationName
148
     * @param bool $inverse
149
     * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
150
     */
151 16
    protected function newMorphToMany(
152
        Builder $query,
153
        Model $parent,
154
        $name,
155
        $table,
156
        $foreignPivotKey,
157
        $relatedPivotKey,
158
        $parentKey,
159
        $relatedKey,
160
        $relationName = null,
161
        $inverse = false
162
    ) {
163 16
        return new MorphToMany(
164
            $query,
165
            $parent,
166
            $name,
167
            $table,
168
            $foreignPivotKey,
169
            $relatedPivotKey,
170
            $parentKey,
171
            $relatedKey,
172
            $relationName,
173
            $inverse
174
        );
175
    }
176
}
177