Passed
Push — dependabot/github_actions/depe... ( d1016c )
by
unknown
11:16
created

HasAranguentRelationships::newBelongsToMany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
c 3
b 0
f 0
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.9666
cc 1
nc 1
nop 8
crap 1

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 LaravelFreelancerNL\Aranguent\Eloquent\Concerns;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo as IlluminateBelongsTo;
8
use Illuminate\Database\Eloquent\Relations\BelongsToMany as IlluminateBelongsToMany;
9
use Illuminate\Database\Eloquent\Relations\HasMany as IlluminateHasMany;
10
use Illuminate\Database\Eloquent\Relations\HasOne as IlluminateHasOne;
11
use Illuminate\Database\Eloquent\Relations\HasOneThrough as IlluminateHasOneThrough;
12
use Illuminate\Database\Eloquent\Relations\MorphMany as IlluminateMorphMany;
13
use Illuminate\Database\Eloquent\Relations\MorphOne as IlluminateMorphOne;
14
use Illuminate\Database\Eloquent\Relations\MorphTo as IlluminateMorphTo;
15
use Illuminate\Database\Eloquent\Relations\MorphToMany as IlluminateMorphToMany;
16
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\BelongsTo;
17
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\BelongsToMany;
18
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\HasMany;
19
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\HasOne;
20
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\HasOneThrough;
21
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\MorphMany;
22
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\MorphOne;
23
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\MorphTo;
24
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\MorphToMany;
25
26
trait HasAranguentRelationships
27
{
28
    /**
29
     * Instantiate a new BelongsTo relationship.
30
     *
31
     * @param  Builder  $query
32
     * @param  Model  $child
33
     * @param  string  $foreignKey
34
     * @param  string  $ownerKey
35
     * @param  string  $relation
36
     * @return IlluminateBelongsTo
37
     */
38 21
    protected function newBelongsTo(Builder $query, Model $child, $foreignKey, $ownerKey, $relation)
39
    {
40 21
        return new BelongsTo($query, $child, $foreignKey, $ownerKey, $relation);
41
    }
42
43
    /**
44
     * Instantiate a new BelongsToMany relationship.
45
     *
46
     * @param  Builder  $query
47
     * @param  Model  $parent
48
     * @param  string  $table
49
     * @param  string  $foreignPivotKey
50
     * @param  string  $relatedPivotKey
51
     * @param  string  $parentKey
52
     * @param  string  $relatedKey
53
     * @param  string|null  $relationName
54
     * @return IlluminateBelongsToMany
55
     */
56 6
    protected function newBelongsToMany(
57
        Builder $query,
58
        Model $parent,
59
        $table,
60
        $foreignPivotKey,
61
        $relatedPivotKey,
62
        $parentKey,
63
        $relatedKey,
64
        $relationName = null
65
    ) {
66 6
        return new BelongsToMany(
67 6
            $query,
68 6
            $parent,
69 6
            $table,
70 6
            $foreignPivotKey,
71 6
            $relatedPivotKey,
72 6
            $parentKey,
73 6
            $relatedKey,
74 6
            $relationName
75 6
        );
76
    }
77
78
    /**
79
     * Instantiate a new HasMany relationship.
80
     *
81
     * @param  Builder  $query
82
     * @param  Model  $parent
83
     * @param  string  $foreignKey
84
     * @param  string  $localKey
85
     * @return IlluminateHasMany
86
     */
87 6
    protected function newHasMany(Builder $query, Model $parent, $foreignKey, $localKey)
88
    {
89 6
        return new HasMany($query, $parent, $foreignKey, $localKey);
90
    }
91
92
    /**
93
     * Instantiate a new HasOne relationship.
94
     *
95
     * @param  Builder  $query
96
     * @param  Model  $parent
97
     * @param  string  $foreignKey
98
     * @param  string  $localKey
99
     * @return IlluminateHasOne
100
     */
101 9
    protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey)
102
    {
103 9
        return new HasOne($query, $parent, $foreignKey, $localKey);
104
    }
105
106
    /**
107
     * Instantiate a new HasOneThrough relationship.
108
     *
109
     * @param  Builder  $query
110
     * @param  Model  $farParent
111
     * @param  Model  $throughParent
112
     * @param  string  $firstKey
113
     * @param  string  $secondKey
114
     * @param  string  $localKey
115
     * @param  string  $secondLocalKey
116
     * @return IlluminateHasOneThrough
117
     */
118
    protected function newHasOneThrough(
119
        Builder $query,
120
        Model $farParent,
121
        Model $throughParent,
122
        $firstKey,
123
        $secondKey,
124
        $localKey,
125
        $secondLocalKey
126
    ) {
127
        return new HasOneThrough($query, $farParent, $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey);
128
    }
129
130
    /**
131
     * Instantiate a new MorphMany relationship.
132
     *
133
     * @param  Builder  $query
134
     * @param  Model  $parent
135
     * @param  string  $type
136
     * @param  string  $id
137
     * @param  string  $localKey
138
     * @return IlluminateMorphMany
139
     */
140 3
    protected function newMorphMany(Builder $query, Model $parent, $type, $id, $localKey)
141
    {
142 3
        return new MorphMany($query, $parent, $type, $id, $localKey);
143
    }
144
145
    /**
146
     * Instantiate a new MorphOne relationship.
147
     *
148
     * @param  Builder  $query
149
     * @param  Model  $parent
150
     * @param  string  $type
151
     * @param  string  $id
152
     * @param  string  $localKey
153
     * @return IlluminateMorphOne
154
     */
155 3
    protected function newMorphOne(Builder $query, Model $parent, $type, $id, $localKey)
156
    {
157 3
        return new MorphOne($query, $parent, $type, $id, $localKey);
158
    }
159
160
    /**
161
     * Instantiate a new MorphTo relationship.
162
     *
163
     * @param  Builder  $query
164
     * @param  Model  $parent
165
     * @param  string  $foreignKey
166
     * @param  string  $ownerKey
167
     * @param  string  $type
168
     * @param  string  $relation
169
     * @return IlluminateMorphTo
170
     */
171 4
    protected function newMorphTo(Builder $query, Model $parent, $foreignKey, $ownerKey, $type, $relation)
172
    {
173 4
        return new MorphTo($query, $parent, $foreignKey, $ownerKey, $type, $relation);
174
    }
175
176
    /**
177
     * Instantiate a new MorphToMany relationship.
178
     *
179
     *  Laravel API PHPMD exclusions
180
     *
181
     *  @SuppressWarnings(PHPMD.BooleanArgumentFlag)
182
     *  @SuppressWarnings(PHPMD.ExcessiveParameterList)
183
     *
184
     * @param  Builder  $query
185
     * @param  Model  $parent
186
     * @param  string  $name
187
     * @param  string  $table
188
     * @param  string  $foreignPivotKey
189
     * @param  string  $relatedPivotKey
190
     * @param  string  $parentKey
191
     * @param  string  $relatedKey
192
     * @param  string|null  $relationName
193
     * @param  bool  $inverse
194
     * @return IlluminateMorphToMany
195
     */
196 8
    protected function newMorphToMany(
197
        Builder $query,
198
        Model $parent,
199
        $name,
200
        $table,
201
        $foreignPivotKey,
202
        $relatedPivotKey,
203
        $parentKey,
204
        $relatedKey,
205
        $relationName = null,
206
        $inverse = false
207
    ) {
208 8
        return new MorphToMany(
209 8
            $query,
210 8
            $parent,
211 8
            $name,
212 8
            $table,
213 8
            $foreignPivotKey,
214 8
            $relatedPivotKey,
215 8
            $parentKey,
216 8
            $relatedKey,
217 8
            $relationName,
218 8
            $inverse
219 8
        );
220
    }
221
}
222