SubjectAction   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 218
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 218
rs 10
c 0
b 0
f 0
wmc 18

18 Methods

Rating   Name   Duplication   Size   Complexity  
A unique() 0 5 1
A cascadeDelete() 0 5 1
A notNull() 0 5 1
A cascade() 0 6 1
A references() 0 5 1
A noAction() 0 6 1
A primaryKey() 0 5 1
A updateAt() 0 5 1
A autIncrement() 0 5 1
A noActionDelete() 0 5 1
A foreignKey() 0 7 1
A timestamps() 0 7 1
A setQueryValueSubject() 0 3 1
A unsigned() 0 5 1
A createAt() 0 5 1
A noActionUpdate() 0 5 1
A default() 0 5 1
A cascadeUpdate() 0 5 1
1
<?php
2
3
namespace Luke\Types;
4
5
6
trait SubjectAction
7
{
8
    /**
9
     * Undocumented function
10
     *
11
     * @return static
12
     */
13
    public function primaryKey(): static
14
    {
15
        $this->setQueryValueSubject("PRIMARY KEY");
16
17
        return $this;
18
    }
19
20
    /**
21
     * @param mixed|null $value
22
     * @return $this
23
     */
24
    public function default(mixed $value = null): static
25
    {
26
        $this->setQueryValueSubject("DEFAULT " . $value);
27
28
        return $this;
29
    }
30
31
    /**
32
     * Undocumented function
33
     *
34
     * @return static
35
     */
36
    public function notNull(): static
37
    {
38
        $this->setQueryValueSubject(" NOT NULL ");
39
40
        return $this;
41
    }
42
43
    /**
44
     * Undocumented function
45
     *
46
     * @return static
47
     */
48
    public function unique(): static
49
    {
50
        $this->setQueryValueSubject(' UNIQUE ');
51
52
        return $this;
53
    }
54
55
    /**
56
     * Undocumented function
57
     *
58
     * @return static
59
     */
60
    public function unsigned(): static
61
    {
62
        $this->setQueryValueSubject(' unsigned ');
63
64
        return $this;
65
    }
66
67
    /**
68
     * Undocumented function
69
     *
70
     * @param string $name
71
     * @return static
72
     */
73
    public function foreignKey(string $name): static
74
    {
75
        $rand = rand();
76
        $constrain = "CONSTRAINT  `" . $name . "_foreignKey_" . $rand . "` ";
77
        $foreignKey = "FOREIGN KEY (`" . $name . "`)";
78
        $this->setQueryValueSubject($constrain . $foreignKey);
79
        return $this;
80
    }
81
82
    /**
83
     * Undocumented function
84
     *
85
     * @param string $name
86
     * @param string $row
87
     * @return static
88
     */
89
    public function references(string $name, string $row = 'id'): static
90
    {
91
        $this->setQueryValueSubject(" REFERENCES `$name` (`$row`)");
92
93
        return $this;
94
    }
95
96
    /**
97
     * Undocumented function
98
     *
99
     * @return static
100
     */
101
    public function cascadeDelete(): static
102
    {
103
        $this->setQueryValueSubject(" ON DELETE CASCADE ");
104
105
        return $this;
106
    }
107
108
    /**
109
     * Undocumented function
110
     *
111
     * @return static
112
     */
113
    public function cascadeUpdate(): static
114
    {
115
        $this->setQueryValueSubject(" ON UPDATE CASCADE ");
116
117
        return $this;
118
    }
119
120
    /**
121
     * Undocumented function
122
     *
123
     * @return static
124
     */
125
    public function cascade(): static
126
    {
127
        $this->cascadeDelete();
128
        $this->cascadeUpdate();
129
130
        return $this;
131
    }
132
133
    /**
134
     * Undocumented function
135
     *
136
     * @return static
137
     */
138
    public function noAction(): static
139
    {
140
        $this->noActionDelete();
141
        $this->noActionUpdate();
142
143
        return $this;
144
    }
145
146
    /**
147
     * Undocumented function
148
     *
149
     * @return static
150
     */
151
    public function noActionDelete(): static
152
    {
153
        $this->setQueryValueSubject(" ON DELETE NO ACTION ");
154
155
        return $this;
156
    }
157
158
    /**
159
     * Undocumented function
160
     *
161
     * @return static
162
     */
163
    public function noActionUpdate(): static
164
    {
165
        $this->setQueryValueSubject(" ON UPDATE NO ACTION ");
166
167
        return $this;
168
    }
169
170
    /**
171
     * Undocumented function
172
     *
173
     * @return static
174
     */
175
    public function autIncrement(): static
176
    {
177
        $this->setQueryValueSubject(" AUTO_INCREMENT ");
178
179
        return $this;
180
    }
181
182
    /**
183
     * Undocumented function
184
     *
185
     * @return static
186
     */
187
    public function timestamps(): static
188
    {
189
        $this->createAt();
190
191
        $this->updateAt();
192
193
        return $this;
194
    }
195
196
    /**
197
     * Undocumented function
198
     *
199
     * @return static
200
     */
201
    public function createAt(): static
202
    {
203
        $this->timestamp('created_at')->notNull()->default('CURRENT_TIMESTAMP');
0 ignored issues
show
Bug introduced by
The method timestamp() does not exist on Luke\Types\SubjectAction. Did you maybe mean timestamps()? ( Ignorable by Annotation )

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

203
        $this->/** @scrutinizer ignore-call */ timestamp('created_at')->notNull()->default('CURRENT_TIMESTAMP');

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...
204
205
        return $this;
206
    }
207
208
    /**
209
     * Undocumented function
210
     *
211
     * @return static
212
     */
213
    public function updateAt(): static
214
    {
215
        $this->timestamp('updated_at')->notNull()->default('CURRENT_TIMESTAMP  ON UPDATE CURRENT_TIMESTAMP');
216
217
        return $this;
218
    }
219
220
    
221
    private function setQueryValueSubject($value)
222
    {
223
        $this->query .= $value;
224
    }
225
}
226