ChronosRelations::newMorphToMany()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 15
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 10
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 Cino\LaravelChronos\Eloquent\Concerns;
4
5
use Cino\LaravelChronos\Eloquent\Relations\BelongsToMany;
6
use Cino\LaravelChronos\Eloquent\Relations\MorphToMany;
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Model;
9
10
trait ChronosRelations
11
{
12
    /**
13
     * Define a many-to-many relationship.
14
     *
15
     * @param string $related
16
     * @param string|null $table
17
     * @param string|null $foreignPivotKey
18
     * @param string|null $relatedPivotKey
19
     * @param string|null $parentKey
20
     * @param string|null $relatedKey
21
     * @param string|null $relation
22
     * @return \Cino\LaravelChronos\Eloquent\Relations\BelongsToMany
23
     */
24 1
    public function belongsToMany(
25
        $related,
26
        $table = null,
27
        $foreignPivotKey = null,
28
        $relatedPivotKey = null,
29
        $parentKey = null,
30
        $relatedKey = null,
31
        $relation = null
32
    ) {
33 1
        return parent::belongsToMany(...func_get_args());
34
    }
35
36
    /**
37
     * Define a polymorphic many-to-many relationship.
38
     *
39
     * @param string $related
40
     * @param string $name
41
     * @param string|null $table
42
     * @param string|null $foreignPivotKey
43
     * @param string|null $relatedPivotKey
44
     * @param string|null $parentKey
45
     * @param string|null $relatedKey
46
     * @param bool $inverse
47
     * @return \Cino\LaravelChronos\Eloquent\Relations\MorphToMany
48
     */
49 1
    public function morphToMany(
50
        $related,
51
        $name,
52
        $table = null,
53
        $foreignPivotKey = null,
54
        $relatedPivotKey = null,
55
        $parentKey = null,
56
        $relatedKey = null,
57
        $inverse = false
58
    ) {
59 1
        return parent::morphToMany(...func_get_args());
60
    }
61
62
    /**
63
     * Define a polymorphic, inverse many-to-many relationship.
64
     *
65
     * @param string $related
66
     * @param string $name
67
     * @param string|null $table
68
     * @param string|null $foreignPivotKey
69
     * @param string|null $relatedPivotKey
70
     * @param string|null $parentKey
71
     * @param string|null $relatedKey
72
     * @return \Cino\LaravelChronos\Eloquent\Relations\MorphToMany
73
     */
74 1
    public function morphedByMany(
75
        $related,
76
        $name,
77
        $table = null,
78
        $foreignPivotKey = null,
79
        $relatedPivotKey = null,
80
        $parentKey = null,
81
        $relatedKey = null
82
    ) {
83 1
        return parent::morphedByMany(...func_get_args());
84
    }
85
86
    /**
87
     * Instantiate a new BelongsToMany relationship.
88
     *
89
     * @param \Illuminate\Database\Eloquent\Builder $query
90
     * @param \Illuminate\Database\Eloquent\Model $parent
91
     * @param string $table
92
     * @param string $foreignPivotKey
93
     * @param string $relatedPivotKey
94
     * @param string $parentKey
95
     * @param string $relatedKey
96
     * @param string|null $relationName
97
     * @return \Cino\LaravelChronos\Eloquent\Relations\BelongsToMany
98
     */
99 1
    protected function newBelongsToMany(
100
        Builder $query,
101
        Model $parent,
102
        $table,
103
        $foreignPivotKey,
104
        $relatedPivotKey,
105
        $parentKey,
106
        $relatedKey,
107
        $relationName = null
108
    ) {
109 1
        return new BelongsToMany($query, $parent, $table, $foreignPivotKey, $relatedPivotKey, $parentKey, $relatedKey,
110 1
            $relationName);
111
    }
112
113
    /**
114
     * Instantiate a new MorphToMany relationship.
115
     *
116
     * @param \Illuminate\Database\Eloquent\Builder $query
117
     * @param \Illuminate\Database\Eloquent\Model $parent
118
     * @param string $name
119
     * @param string $table
120
     * @param string $foreignPivotKey
121
     * @param string $relatedPivotKey
122
     * @param string $parentKey
123
     * @param string $relatedKey
124
     * @param string|null $relationName
125
     * @param bool $inverse
126
     * @return \Cino\LaravelChronos\Eloquent\Relations\MorphToMany
127
     */
128 1
    protected function newMorphToMany(
129
        Builder $query,
130
        Model $parent,
131
        $name,
132
        $table,
133
        $foreignPivotKey,
134
        $relatedPivotKey,
135
        $parentKey,
136
        $relatedKey,
137
        $relationName = null,
138
        $inverse = false
139
    ) {
140 1
        return new MorphToMany($query, $parent, $name, $table, $foreignPivotKey, $relatedPivotKey, $parentKey,
141 1
            $relatedKey,
142 1
            $relationName, $inverse);
143
    }
144
145
}
146