Issues (51)

src/Concerns/MorphsTo.php (11 issues)

1
<?php
2
3
namespace Reedware\LaravelBlueprints\Concerns;
4
5
use Illuminate\Support\Str;
6
7
trait MorphsTo
8
{
9
    /**
10
	 * Defines a Belongs To Column and Relationship.
11
	 *
12
     * @param  string       $morphable
13
     * @param  string|null  $index
14
     *
15
     * @return \Reed\Blueprints\Columns
0 ignored issues
show
The type Reed\Blueprints\Columns was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
	 */
17
    public function morphsTo($morphable, $index = null)
0 ignored issues
show
The parameter $index is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

17
    public function morphsTo($morphable, /** @scrutinizer ignore-unused */ $index = null)

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

Loading history...
18
    {
19
        // Define the ID
20
        $id = $this->morphsToIdColumn($morphable);
21
22
    	// Define the Type
23
    	$type = $this->morphsToTypeColumn($morphable);
24
25
        // Return the Columns
26
        return $this->newColumns([$id, $type]);
0 ignored issues
show
It seems like newColumns() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        return $this->/** @scrutinizer ignore-call */ newColumns([$id, $type]);
Loading history...
27
    }
28
29
    /**
30
	 * Defines a Belongs To Column and Relationship using a Big Integer.
31
	 *
32
     * @param  string       $morphable
33
     * @param  string|null  $index
34
     *
35
     * @return \Reed\Blueprints\Columns
36
	 */
37
    public function bigMorphsTo($morphable, $index = null)
0 ignored issues
show
The parameter $index is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

37
    public function bigMorphsTo($morphable, /** @scrutinizer ignore-unused */ $index = null)

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

Loading history...
38
    {
39
        // Define the ID
40
        $id = $this->bigMorphsToIdColumn($morphable);
41
42
        // Define the Type
43
        $type = $this->morphsToTypeColumn($morphable);
44
45
        // Return the Columns
46
        return $this->newColumns([$id, $type]);
47
    }
48
49
    /**
50
     * Defines a Morphs To ID Column.
51
     *
52
     * @param  string   $morphable
53
     * @param  boolean  $big
54
     *
55
     * @return \Illuminate\Support\Fluent
56
     */
57
    public function morphsToIdColumn($morphable, $big = false)
58
    {
59
        return $this->belongsToColumn($this->getMorphableId($morphable), $big);
0 ignored issues
show
It seems like belongsToColumn() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        return $this->/** @scrutinizer ignore-call */ belongsToColumn($this->getMorphableId($morphable), $big);
Loading history...
60
    }
61
62
    /**
63
     * Defines a Big Morphs To ID Column.
64
     *
65
     * @param  string  $morphable
66
     *
67
     * @return \Illuminate\Support\Fluent
68
     */
69
    public function bigMorphsToIdColumn($morphable)
70
    {
71
        return $this->morphToIdColumn($morphable, true);
0 ignored issues
show
The method morphToIdColumn() does not exist on Reedware\LaravelBlueprints\Concerns\MorphsTo. Did you maybe mean morphsToIdColumn()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        return $this->/** @scrutinizer ignore-call */ morphToIdColumn($morphable, true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
    }
73
74
    /**
75
     * Defines a Morphs To Type Column.
76
     *
77
     * @param  string   $morphable
78
     * @param  boolean  $big
79
     *
80
     * @return \Illuminate\Support\Fluent
81
     */
82
    public function morphsToTypeColumn($morphable, $big = false)
0 ignored issues
show
The parameter $big is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

82
    public function morphsToTypeColumn($morphable, /** @scrutinizer ignore-unused */ $big = false)

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

Loading history...
83
    {
84
        return $this->string($this->getMorphableType($morphable), 255);
0 ignored issues
show
It seems like string() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
        return $this->/** @scrutinizer ignore-call */ string($this->getMorphableType($morphable), 255);
Loading history...
85
    }
86
87
    /**
88
     * Drops a Belongs To Relationship.
89
     *
90
     * @param  string       $morphable
91
     * @param  string|null  $index
92
     *
93
     * @return void
94
     */
95
    public function dropMorphsTo($morphable)
96
    {
97
        // Drop the ID Column
98
        $this->dropMorphsToIdColumn($morphable);
99
100
        // Drop the Type Column
101
        $this->dropMorphsToIndex($morphable);
0 ignored issues
show
The method dropMorphsToIndex() does not exist on Reedware\LaravelBlueprints\Concerns\MorphsTo. Did you maybe mean dropMorphsTo()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
        $this->/** @scrutinizer ignore-call */ 
102
               dropMorphsToIndex($morphable);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
    }
103
104
    /**
105
     * Drops a Morphs To ID Column.
106
     *
107
     * @param  string  $morphable
108
     *
109
     * @return \Illuminate\Support\Fluent
110
     */
111
    public function dropMorphsToIdColumn($morphable)
112
    {
113
        $this->dropBelongsToColumn($this->getMorphableId($morphable));
0 ignored issues
show
It seems like dropBelongsToColumn() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
        $this->/** @scrutinizer ignore-call */ 
114
               dropBelongsToColumn($this->getMorphableId($morphable));
Loading history...
114
    }
115
116
    /**
117
     * Drops a Morphs To Type Column.
118
     *
119
     * @param  string  $morphable
120
     *
121
     * @return \Illuminate\Support\Fluent
122
     */
123
    public function dropMorphsToTypeColumn($morphable)
124
    {
125
        $this->dropColumn($this->getMorphableType($morphable));
0 ignored issues
show
It seems like dropColumn() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

125
        $this->/** @scrutinizer ignore-call */ 
126
               dropColumn($this->getMorphableType($morphable));
Loading history...
126
    }
127
128
    /**
129
     * Returns the Name of the Morphable ID Column.
130
     *
131
     * @param  string  $morphable
132
     *
133
     * @return string
134
     */
135
    public function getMorphableId($morphable)
136
    {
137
        return $morphable . '_id';
138
    }
139
140
    /**
141
     * Returns the Name of the Morphable Type Column.
142
     *
143
     * @param  string  $morphable
144
     *
145
     * @return string
146
     */
147
    public function getMorphableType($morphable)
148
    {
149
        return $morphable . '_type';
150
    }
151
}