Passed
Pull Request — master (#372)
by Wilmer
03:26
created

QueryBuilderColumnsTypeTrait::columnTypes()   C

Complexity

Conditions 9
Paths 192

Size

Total Lines 977
Code Lines 568

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 568
c 0
b 0
f 0
nc 192
nop 0
dl 0
loc 977
rs 5.8311

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests;
6
7
use Yiisoft\Db\Schema\Schema;
8
9
trait QueryBuilderColumnsTypeTrait
10
{
11
    /**
12
     * This is not used as a dataprovider for testGetColumnType to speed up the test when used as dataprovider every
13
     * single line will cause a reconnect with the database which is not needed here.
14
     */
15
    public function columnTypes(): array
16
    {
17
        $version = $this->db->getServerVersion();
18
19
        $items = [
20
            [
21
                Schema::TYPE_BIGINT,
22
                $this->bigInteger(),
0 ignored issues
show
Bug introduced by
It seems like bigInteger() 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

22
                $this->/** @scrutinizer ignore-call */ 
23
                       bigInteger(),
Loading history...
23
                [
24
                    'mysql' => 'bigint(20)',
25
                    'pgsql' => 'bigint',
26
                    'sqlite' => 'bigint',
27
                    'oci' => 'NUMBER(20)',
28
                    'sqlsrv' => 'bigint',
29
                ],
30
            ],
31
            [
32
                Schema::TYPE_BIGINT . ' NOT NULL',
33
                $this->bigInteger()->notNull(),
34
                [
35
                    'mysql' => 'bigint(20) NOT NULL',
36
                    'pgsql' => 'bigint NOT NULL',
37
                    'sqlite' => 'bigint NOT NULL',
38
                    'oci' => 'NUMBER(20) NOT NULL',
39
                    'sqlsrv' => 'bigint NOT NULL',
40
                ],
41
            ],
42
            [
43
                Schema::TYPE_BIGINT . ' CHECK (value > 5)',
44
                $this->bigInteger()->check('value > 5'),
45
                [
46
                    'mysql' => 'bigint(20) CHECK (value > 5)',
47
                    'pgsql' => 'bigint CHECK (value > 5)',
48
                    'sqlite' => 'bigint CHECK (value > 5)',
49
                    'oci' => 'NUMBER(20) CHECK (value > 5)',
50
                    'sqlsrv' => 'bigint CHECK (value > 5)',
51
                ],
52
            ],
53
            [
54
                Schema::TYPE_BIGINT . '(8)',
55
                $this->bigInteger(8),
56
                [
57
                    'mysql' => 'bigint(8)',
58
                    'pgsql' => 'bigint',
59
                    'sqlite' => 'bigint',
60
                    'oci' => 'NUMBER(8)',
61
                    'sqlsrv' => 'bigint',
62
                ],
63
            ],
64
            [
65
                Schema::TYPE_BIGINT . '(8) CHECK (value > 5)',
66
                $this->bigInteger(8)->check('value > 5'),
67
                [
68
                    'mysql' => 'bigint(8) CHECK (value > 5)',
69
                    'pgsql' => 'bigint CHECK (value > 5)',
70
                    'sqlite' => 'bigint CHECK (value > 5)',
71
                    'oci' => 'NUMBER(8) CHECK (value > 5)',
72
                    'sqlsrv' => 'bigint CHECK (value > 5)',
73
                ],
74
            ],
75
            [
76
                Schema::TYPE_BIGPK,
77
                $this->bigPrimaryKey(),
0 ignored issues
show
Bug introduced by
It seems like bigPrimaryKey() 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

77
                $this->/** @scrutinizer ignore-call */ 
78
                       bigPrimaryKey(),
Loading history...
78
                [
79
                    'mysql' => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY',
80
                    'pgsql' => 'bigserial NOT NULL PRIMARY KEY',
81
                    'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
82
                ],
83
            ],
84
            [
85
                Schema::TYPE_BINARY,
86
                $this->binary(),
0 ignored issues
show
Bug introduced by
It seems like binary() 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

86
                $this->/** @scrutinizer ignore-call */ 
87
                       binary(),
Loading history...
87
                [
88
                    'mysql' => 'blob',
89
                    'pgsql' => 'bytea',
90
                    'sqlite' => 'blob',
91
                    'oci' => 'BLOB',
92
                    'sqlsrv' => 'varbinary(max)',
93
                ],
94
            ],
95
            [
96
                Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1',
97
                $this->boolean()->notNull()->defaultValue(1),
0 ignored issues
show
Bug introduced by
It seems like boolean() 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

97
                $this->/** @scrutinizer ignore-call */ 
98
                       boolean()->notNull()->defaultValue(1),
Loading history...
98
                [
99
                    'mysql' => 'tinyint(1) NOT NULL DEFAULT 1',
100
                    'sqlite' => 'boolean NOT NULL DEFAULT 1',
101
                    'sqlsrv' => 'bit NOT NULL DEFAULT 1',
102
                ],
103
            ],
104
            [
105
                Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT TRUE',
106
                $this->boolean()->notNull()->defaultValue(true),
107
                [
108
                    'pgsql' => 'boolean NOT NULL DEFAULT TRUE',
109
                ],
110
            ],
111
            [
112
                Schema::TYPE_BOOLEAN,
113
                $this->boolean(),
114
                [
115
                    'mysql' => 'tinyint(1)',
116
                    'pgsql' => 'boolean',
117
                    'sqlite' => 'boolean',
118
                    'oci' => 'NUMBER(1)',
119
                    'sqlsrv' => 'bit',
120
                ],
121
            ],
122
            [
123
                Schema::TYPE_CHAR . ' CHECK (value LIKE \'test%\')',
124
                $this->char()->check('value LIKE \'test%\''),
0 ignored issues
show
Bug introduced by
It seems like char() 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

124
                $this->/** @scrutinizer ignore-call */ 
125
                       char()->check('value LIKE \'test%\''),
Loading history...
125
                [
126
                    'pgsql' => 'char(1) CHECK (value LIKE \'test%\')',
127
                ],
128
            ],
129
            [
130
                Schema::TYPE_CHAR . ' CHECK (value LIKE "test%")',
131
                $this->char()->check('value LIKE "test%"'),
132
                [
133
                    'mysql' => 'char(1) CHECK (value LIKE "test%")',
134
                    'sqlite' => 'char(1) CHECK (value LIKE "test%")',
135
                ],
136
            ],
137
            [
138
                Schema::TYPE_CHAR . ' NOT NULL',
139
                $this->char()->notNull(),
140
                [
141
                    'mysql' => 'char(1) NOT NULL',
142
                    'pgsql' => 'char(1) NOT NULL',
143
                    'sqlite' => 'char(1) NOT NULL',
144
                    'oci' => 'CHAR(1) NOT NULL',
145
                ],
146
            ],
147
            [
148
                Schema::TYPE_CHAR . '(6) CHECK (value LIKE "test%")',
149
                $this->char(6)->check('value LIKE "test%"'),
150
                [
151
                    'mysql' => 'char(6) CHECK (value LIKE "test%")',
152
                    'sqlite' => 'char(6) CHECK (value LIKE "test%")',
153
                ],
154
            ],
155
            [
156
                Schema::TYPE_CHAR . '(6)',
157
                $this->char(6)->unsigned(),
158
                [
159
                    'pgsql' => 'char(6)',
160
                ],
161
            ],
162
            [
163
                Schema::TYPE_CHAR . '(6)',
164
                $this->char(6),
165
                [
166
                    'mysql' => 'char(6)',
167
                    'pgsql' => 'char(6)',
168
                    'sqlite' => 'char(6)',
169
                    'oci' => 'CHAR(6)',
170
                ],
171
            ],
172
            [
173
                Schema::TYPE_CHAR,
174
                $this->char(),
175
                [
176
                    'mysql' => 'char(1)',
177
                    'pgsql' => 'char(1)',
178
                    'sqlite' => 'char(1)',
179
                    'oci' => 'CHAR(1)',
180
                ],
181
            ],
182
            [
183
                Schema::TYPE_DATE . ' NOT NULL',
184
                $this->date()->notNull(),
0 ignored issues
show
Bug introduced by
It seems like date() 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

184
                $this->/** @scrutinizer ignore-call */ 
185
                       date()->notNull(),
Loading history...
185
                [
186
                    'pgsql' => 'date NOT NULL',
187
                    'sqlite' => 'date NOT NULL',
188
                    'oci' => 'DATE NOT NULL',
189
                    'sqlsrv' => 'date NOT NULL',
190
                ],
191
            ],
192
            [
193
                Schema::TYPE_DATE,
194
                $this->date(),
195
                [
196
                    'mysql' => 'date',
197
                    'pgsql' => 'date',
198
                    'sqlite' => 'date',
199
                    'oci' => 'DATE',
200
                    'sqlsrv' => 'date',
201
                ],
202
            ],
203
            [
204
                Schema::TYPE_DATETIME . ' NOT NULL',
205
                $this->dateTime()->notNull(),
0 ignored issues
show
Bug introduced by
It seems like dateTime() 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

205
                $this->/** @scrutinizer ignore-call */ 
206
                       dateTime()->notNull(),
Loading history...
206
                [
207
                    'mysql' => version_compare($version, '5.6.4', '>=') ? 'datetime(0) NOT NULL' : 'datetime NOT NULL',
208
                    'pgsql' => 'timestamp(0) NOT NULL',
209
                    'sqlite' => 'datetime NOT NULL',
210
                    'oci' => 'TIMESTAMP NOT NULL',
211
                    'sqlsrv' => 'datetime NOT NULL',
212
                ],
213
            ],
214
            [
215
                Schema::TYPE_DATETIME,
216
                $this->dateTime(),
217
                [
218
                    'mysql' => version_compare($version, '5.6.4', '>=') ? 'datetime(0)' : 'datetime',
219
                    'pgsql' => 'timestamp(0)',
220
                    'sqlite' => 'datetime',
221
                    'oci' => 'TIMESTAMP',
222
                    'sqlsrv' => 'datetime',
223
                ],
224
            ],
225
            [
226
                Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)',
227
                $this->decimal()->check('value > 5.6'),
0 ignored issues
show
Bug introduced by
It seems like decimal() 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

227
                $this->/** @scrutinizer ignore-call */ 
228
                       decimal()->check('value > 5.6'),
Loading history...
228
                [
229
                    'mysql' => 'decimal(10,0) CHECK (value > 5.6)',
230
                    'pgsql' => 'numeric(10,0) CHECK (value > 5.6)',
231
                    'sqlite' => 'decimal(10,0) CHECK (value > 5.6)',
232
                    'oci' => 'NUMBER CHECK (value > 5.6)',
233
                    'sqlsrv' => 'decimal(18,0) CHECK (value > 5.6)',
234
                ],
235
            ],
236
            [
237
                Schema::TYPE_DECIMAL . ' NOT NULL',
238
                $this->decimal()->notNull(),
239
                [
240
                    'mysql' => 'decimal(10,0) NOT NULL',
241
                    'pgsql' => 'numeric(10,0) NOT NULL',
242
                    'sqlite' => 'decimal(10,0) NOT NULL',
243
                    'oci' => 'NUMBER NOT NULL',
244
                    'sqlsrv' => 'decimal(18,0) NOT NULL',
245
                ],
246
            ],
247
            [
248
                Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)',
249
                $this->decimal(12, 4)->check('value > 5.6'),
250
                [
251
                    'mysql' => 'decimal(12,4) CHECK (value > 5.6)',
252
                    'pgsql' => 'numeric(12,4) CHECK (value > 5.6)',
253
                    'sqlite' => 'decimal(12,4) CHECK (value > 5.6)',
254
                    'oci' => 'NUMBER CHECK (value > 5.6)',
255
                    'sqlsrv' => 'decimal(12,4) CHECK (value > 5.6)',
256
                ],
257
            ],
258
            [
259
                Schema::TYPE_DECIMAL . '(12,4)',
260
                $this->decimal(12, 4),
261
                [
262
                    'mysql' => 'decimal(12,4)',
263
                    'pgsql' => 'numeric(12,4)',
264
                    'sqlite' => 'decimal(12,4)',
265
                    'oci' => 'NUMBER',
266
                    'sqlsrv' => 'decimal(12,4)',
267
                ],
268
            ],
269
            [
270
                Schema::TYPE_DECIMAL,
271
                $this->decimal(),
272
                [
273
                    'mysql' => 'decimal(10,0)',
274
                    'pgsql' => 'numeric(10,0)',
275
                    'sqlite' => 'decimal(10,0)',
276
                    'oci' => 'NUMBER',
277
                    'sqlsrv' => 'decimal(18,0)',
278
                ],
279
            ],
280
            [
281
                Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)',
282
                $this->double()->check('value > 5.6'),
0 ignored issues
show
Bug introduced by
It seems like double() 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

282
                $this->/** @scrutinizer ignore-call */ 
283
                       double()->check('value > 5.6'),
Loading history...
283
                [
284
                    'mysql' => 'double CHECK (value > 5.6)',
285
                    'pgsql' => 'double precision CHECK (value > 5.6)',
286
                    'sqlite' => 'double CHECK (value > 5.6)',
287
                    'oci' => 'NUMBER CHECK (value > 5.6)',
288
                    'sqlsrv' => 'float CHECK (value > 5.6)',
289
                ],
290
            ],
291
            [
292
                Schema::TYPE_DOUBLE . ' NOT NULL',
293
                $this->double()->notNull(),
294
                [
295
                    'mysql' => 'double NOT NULL',
296
                    'pgsql' => 'double precision NOT NULL',
297
                    'sqlite' => 'double NOT NULL',
298
                    'oci' => 'NUMBER NOT NULL',
299
                    'sqlsrv' => 'float NOT NULL',
300
                ],
301
            ],
302
            [
303
                Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)',
304
                $this->double(16)->check('value > 5.6'),
305
                [
306
                    'mysql' => 'double CHECK (value > 5.6)',
307
                    'pgsql' => 'double precision CHECK (value > 5.6)',
308
                    'sqlite' => 'double CHECK (value > 5.6)',
309
                    'oci' => 'NUMBER CHECK (value > 5.6)',
310
                    'sqlsrv' => 'float CHECK (value > 5.6)',
311
                ],
312
            ],
313
            [
314
                Schema::TYPE_DOUBLE . '(16)',
315
                $this->double(16),
316
                [
317
                    'mysql' => 'double',
318
                    'sqlite' => 'double',
319
                    'oci' => 'NUMBER',
320
                    'sqlsrv' => 'float',
321
                ],
322
            ],
323
            [
324
                Schema::TYPE_DOUBLE,
325
                $this->double(),
326
                [
327
                    'mysql' => 'double',
328
                    'pgsql' => 'double precision',
329
                    'sqlite' => 'double',
330
                    'oci' => 'NUMBER',
331
                    'sqlsrv' => 'float',
332
                ],
333
            ],
334
            [
335
                Schema::TYPE_FLOAT . ' CHECK (value > 5.6)',
336
                $this->float()->check('value > 5.6'),
0 ignored issues
show
Bug introduced by
It seems like float() 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

336
                $this->/** @scrutinizer ignore-call */ 
337
                       float()->check('value > 5.6'),
Loading history...
337
                [
338
                    'mysql' => 'float CHECK (value > 5.6)',
339
                    'pgsql' => 'double precision CHECK (value > 5.6)',
340
                    'sqlite' => 'float CHECK (value > 5.6)',
341
                    'oci' => 'NUMBER CHECK (value > 5.6)',
342
                    'sqlsrv' => 'float CHECK (value > 5.6)',
343
                ],
344
            ],
345
            [
346
                Schema::TYPE_FLOAT . ' NOT NULL',
347
                $this->float()->notNull(),
348
                [
349
                    'mysql' => 'float NOT NULL',
350
                    'pgsql' => 'double precision NOT NULL',
351
                    'sqlite' => 'float NOT NULL',
352
                    'oci' => 'NUMBER NOT NULL',
353
                    'sqlsrv' => 'float NOT NULL',
354
                ],
355
            ],
356
            [
357
                Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)',
358
                $this->float(16)->check('value > 5.6'),
359
                [
360
                    'mysql' => 'float CHECK (value > 5.6)',
361
                    'pgsql' => 'double precision CHECK (value > 5.6)',
362
                    'sqlite' => 'float CHECK (value > 5.6)',
363
                    'oci' => 'NUMBER CHECK (value > 5.6)',
364
                    'sqlsrv' => 'float CHECK (value > 5.6)',
365
                ],
366
            ],
367
            [
368
                Schema::TYPE_FLOAT . '(16)',
369
                $this->float(16),
370
                [
371
                    'mysql' => 'float',
372
                    'sqlite' => 'float',
373
                    'oci' => 'NUMBER',
374
                    'sqlsrv' => 'float',
375
                ],
376
            ],
377
            [
378
                Schema::TYPE_FLOAT,
379
                $this->float(),
380
                [
381
                    'mysql' => 'float',
382
                    'pgsql' => 'double precision',
383
                    'sqlite' => 'float',
384
                    'oci' => 'NUMBER',
385
                    'sqlsrv' => 'float',
386
                ],
387
            ],
388
            [
389
                Schema::TYPE_INTEGER . ' CHECK (value > 5)',
390
                $this->integer()->check('value > 5'),
0 ignored issues
show
Bug introduced by
It seems like integer() 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

390
                $this->/** @scrutinizer ignore-call */ 
391
                       integer()->check('value > 5'),
Loading history...
391
                [
392
                    'mysql' => 'int(11) CHECK (value > 5)',
393
                    'pgsql' => 'integer CHECK (value > 5)',
394
                    'sqlite' => 'integer CHECK (value > 5)',
395
                    'oci' => 'NUMBER(10) CHECK (value > 5)',
396
                    'sqlsrv' => 'int CHECK (value > 5)',
397
                ],
398
            ],
399
            [
400
                Schema::TYPE_INTEGER . ' NOT NULL',
401
                $this->integer()->notNull(),
402
                [
403
                    'mysql' => 'int(11) NOT NULL',
404
                    'pgsql' => 'integer NOT NULL',
405
                    'sqlite' => 'integer NOT NULL',
406
                    'oci' => 'NUMBER(10) NOT NULL',
407
                    'sqlsrv' => 'int NOT NULL',
408
                ],
409
            ],
410
            [
411
                Schema::TYPE_INTEGER . '(8) CHECK (value > 5)',
412
                $this->integer(8)->check('value > 5'),
413
                [
414
                    'mysql' => 'int(8) CHECK (value > 5)',
415
                    'pgsql' => 'integer CHECK (value > 5)',
416
                    'sqlite' => 'integer CHECK (value > 5)',
417
                    'oci' => 'NUMBER(8) CHECK (value > 5)',
418
                    'sqlsrv' => 'int CHECK (value > 5)',
419
                ],
420
            ],
421
            [
422
                Schema::TYPE_INTEGER . '(8)',
423
                $this->integer(8)->unsigned(),
424
                [
425
                    'pgsql' => 'integer',
426
                ],
427
            ],
428
            [
429
                Schema::TYPE_INTEGER . '(8)',
430
                $this->integer(8),
431
                [
432
                    'mysql' => 'int(8)',
433
                    'pgsql' => 'integer',
434
                    'sqlite' => 'integer',
435
                    'oci' => 'NUMBER(8)',
436
                    'sqlsrv' => 'int',
437
                ],
438
            ],
439
            [
440
                Schema::TYPE_INTEGER,
441
                $this->integer(),
442
                [
443
                    'mysql' => 'int(11)',
444
                    'pgsql' => 'integer',
445
                    'sqlite' => 'integer',
446
                    'oci' => 'NUMBER(10)',
447
                    'sqlsrv' => 'int',
448
                ],
449
            ],
450
            [
451
                Schema::TYPE_MONEY . ' CHECK (value > 0.0)',
452
                $this->money()->check('value > 0.0'),
0 ignored issues
show
Bug introduced by
It seems like money() 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

452
                $this->/** @scrutinizer ignore-call */ 
453
                       money()->check('value > 0.0'),
Loading history...
453
                [
454
                    'mysql' => 'decimal(19,4) CHECK (value > 0.0)',
455
                    'pgsql' => 'numeric(19,4) CHECK (value > 0.0)',
456
                    'sqlite' => 'decimal(19,4) CHECK (value > 0.0)',
457
                    'oci' => 'NUMBER(19,4) CHECK (value > 0.0)',
458
                    'sqlsrv' => 'decimal(19,4) CHECK (value > 0.0)',
459
                ],
460
            ],
461
            [
462
                Schema::TYPE_MONEY . ' NOT NULL',
463
                $this->money()->notNull(),
464
                [
465
                    'mysql' => 'decimal(19,4) NOT NULL',
466
                    'pgsql' => 'numeric(19,4) NOT NULL',
467
                    'sqlite' => 'decimal(19,4) NOT NULL',
468
                    'oci' => 'NUMBER(19,4) NOT NULL',
469
                    'sqlsrv' => 'decimal(19,4) NOT NULL',
470
                ],
471
            ],
472
            [
473
                Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)',
474
                $this->money(16, 2)->check('value > 0.0'),
475
                [
476
                    'mysql' => 'decimal(16,2) CHECK (value > 0.0)',
477
                    'pgsql' => 'numeric(16,2) CHECK (value > 0.0)',
478
                    'sqlite' => 'decimal(16,2) CHECK (value > 0.0)',
479
                    'oci' => 'NUMBER(16,2) CHECK (value > 0.0)',
480
                    'sqlsrv' => 'decimal(16,2) CHECK (value > 0.0)',
481
                ],
482
            ],
483
            [
484
                Schema::TYPE_MONEY . '(16,2)',
485
                $this->money(16, 2),
486
                [
487
                    'mysql' => 'decimal(16,2)',
488
                    'pgsql' => 'numeric(16,2)',
489
                    'sqlite' => 'decimal(16,2)',
490
                    'oci' => 'NUMBER(16,2)',
491
                    'sqlsrv' => 'decimal(16,2)',
492
                ],
493
            ],
494
            [
495
                Schema::TYPE_MONEY,
496
                $this->money(),
497
                [
498
                    'mysql' => 'decimal(19,4)',
499
                    'pgsql' => 'numeric(19,4)',
500
                    'sqlite' => 'decimal(19,4)',
501
                    'oci' => 'NUMBER(19,4)',
502
                    'sqlsrv' => 'decimal(19,4)',
503
                ],
504
            ],
505
            [
506
                Schema::TYPE_PK . ' AFTER `col_before`',
507
                $this->primaryKey()->after('col_before'),
0 ignored issues
show
Bug introduced by
It seems like primaryKey() 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

507
                $this->/** @scrutinizer ignore-call */ 
508
                       primaryKey()->after('col_before'),
Loading history...
508
                [
509
                    'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY AFTER `col_before`',
510
                ],
511
            ],
512
            [
513
                Schema::TYPE_PK . ' FIRST',
514
                $this->primaryKey()->first(),
515
                [
516
                    'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST',
517
                ],
518
            ],
519
            [
520
                Schema::TYPE_PK . ' FIRST',
521
                $this->primaryKey()->first()->after('col_before'),
522
                [
523
                    'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST',
524
                ],
525
                [
526
                    'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
527
                ],
528
            ],
529
            [
530
                Schema::TYPE_PK . '(8) AFTER `col_before`',
531
                $this->primaryKey(8)->after('col_before'),
532
                [
533
                    'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY AFTER `col_before`',
534
                ],
535
            ],
536
            [
537
                Schema::TYPE_PK . '(8) FIRST',
538
                $this->primaryKey(8)->first(),
539
                [
540
                    'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST',
541
                ],
542
            ],
543
            [
544
                Schema::TYPE_PK . '(8) FIRST',
545
                $this->primaryKey(8)->first()->after('col_before'),
546
                [
547
                    'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST',
548
                ],
549
            ],
550
            [
551
                Schema::TYPE_PK . " COMMENT 'test' AFTER `col_before`",
552
                $this->primaryKey()->comment('test')->after('col_before'),
553
                [
554
                    'mysql' => "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test' AFTER `col_before`",
555
                ],
556
            ],
557
            [
558
                Schema::TYPE_PK . " COMMENT 'testing \'quote\'' AFTER `col_before`",
559
                $this->primaryKey()->comment('testing \'quote\'')->after('col_before'),
560
                [
561
                    'mysql' => "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'testing \'quote\''"
562
                        . ' AFTER `col_before`',
563
                ],
564
            ],
565
            [
566
                Schema::TYPE_PK . ' CHECK (value > 5)',
567
                $this->primaryKey()->check('value > 5'),
568
                [
569
                    'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)',
570
                    'pgsql' => 'serial NOT NULL PRIMARY KEY CHECK (value > 5)',
571
                    'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (value > 5)',
572
                    'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY CHECK (value > 5)',
573
                    'sqlsrv' => 'int IDENTITY PRIMARY KEY CHECK (value > 5)',
574
                ],
575
            ],
576
            [
577
                Schema::TYPE_PK . '(8) CHECK (value > 5)',
578
                $this->primaryKey(8)->check('value > 5'),
579
                [
580
                    'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)',
581
                    'oci' => 'NUMBER(8) NOT NULL PRIMARY KEY CHECK (value > 5)',
582
                ],
583
            ],
584
            [
585
                Schema::TYPE_PK . '(8)',
586
                $this->primaryKey(8),
587
                [
588
                    'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY',
589
                    'oci' => 'NUMBER(8) NOT NULL PRIMARY KEY',
590
                ],
591
            ],
592
            [
593
                Schema::TYPE_PK,
594
                $this->primaryKey(),
595
                [
596
                    'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY',
597
                    'pgsql' => 'serial NOT NULL PRIMARY KEY',
598
                    'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
599
                    'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY',
600
                    'sqlsrv' => 'int IDENTITY PRIMARY KEY',
601
                ],
602
            ],
603
            [
604
                Schema::TYPE_TINYINT . '(2)',
605
                $this->tinyInteger(2),
0 ignored issues
show
Bug introduced by
It seems like tinyInteger() 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

605
                $this->/** @scrutinizer ignore-call */ 
606
                       tinyInteger(2),
Loading history...
606
                [
607
                    'mysql' => 'tinyint(2)',
608
                    'pgsql' => 'smallint',
609
                    'sqlite' => 'tinyint',
610
                    'oci' => 'NUMBER(2)',
611
                    'sqlsrv' => 'tinyint',
612
                ],
613
            ],
614
            [
615
                Schema::TYPE_TINYINT . ' UNSIGNED',
616
                $this->tinyInteger()->unsigned(),
617
                [
618
                    'mysql' => 'tinyint(3) UNSIGNED',
619
                    'sqlite' => 'tinyint UNSIGNED',
620
                ],
621
            ],
622
            [
623
                Schema::TYPE_TINYINT,
624
                $this->tinyInteger(),
625
                [
626
                    'mysql' => 'tinyint(3)',
627
                    'pgsql' => 'smallint',
628
                    'sqlite' => 'tinyint',
629
                    'oci' => 'NUMBER(3)',
630
                    'sqlsrv' => 'tinyint',
631
                ],
632
            ],
633
            [
634
                Schema::TYPE_SMALLINT . '(8)',
635
                $this->smallInteger(8),
0 ignored issues
show
Bug introduced by
It seems like smallInteger() 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

635
                $this->/** @scrutinizer ignore-call */ 
636
                       smallInteger(8),
Loading history...
636
                [
637
                    'mysql' => 'smallint(8)',
638
                    'pgsql' => 'smallint',
639
                    'sqlite' => 'smallint',
640
                    'oci' => 'NUMBER(8)',
641
                    'sqlsrv' => 'smallint',
642
                ],
643
            ],
644
            [
645
                Schema::TYPE_SMALLINT,
646
                $this->smallInteger(),
647
                [
648
                    'mysql' => 'smallint(6)',
649
                    'pgsql' => 'smallint',
650
                    'sqlite' => 'smallint',
651
                    'oci' => 'NUMBER(5)',
652
                    'sqlsrv' => 'smallint',
653
                ],
654
            ],
655
            [
656
                Schema::TYPE_STRING . " CHECK (value LIKE 'test%')",
657
                $this->string()->check("value LIKE 'test%'"),
0 ignored issues
show
Bug introduced by
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

657
                $this->/** @scrutinizer ignore-call */ 
658
                       string()->check("value LIKE 'test%'"),
Loading history...
658
                [
659
                    'mysql' => "varchar(255) CHECK (value LIKE 'test%')",
660
                    'sqlite' => "varchar(255) CHECK (value LIKE 'test%')",
661
                    'sqlsrv' => "nvarchar(255) CHECK (value LIKE 'test%')",
662
                ],
663
            ],
664
            [
665
                Schema::TYPE_STRING . ' CHECK (value LIKE \'test%\')',
666
                $this->string()->check('value LIKE \'test%\''),
667
                [
668
                    'pgsql' => 'varchar(255) CHECK (value LIKE \'test%\')',
669
                    'oci' => 'VARCHAR2(255) CHECK (value LIKE \'test%\')',
670
                ],
671
            ],
672
            [
673
                Schema::TYPE_STRING . ' NOT NULL',
674
                $this->string()->notNull(),
675
                [
676
                    'mysql' => 'varchar(255) NOT NULL',
677
                    'pgsql' => 'varchar(255) NOT NULL',
678
                    'sqlite' => 'varchar(255) NOT NULL',
679
                    'oci' => 'VARCHAR2(255) NOT NULL',
680
                    'sqlsrv' => 'nvarchar(255) NOT NULL',
681
                ],
682
            ],
683
            [
684
                Schema::TYPE_STRING . "(32) CHECK (value LIKE 'test%')",
685
                $this->string(32)->check("value LIKE 'test%'"),
686
                [
687
                    'mysql' => "varchar(32) CHECK (value LIKE 'test%')",
688
                    'sqlite' => "varchar(32) CHECK (value LIKE 'test%')",
689
                    'sqlsrv' => "nvarchar(32) CHECK (value LIKE 'test%')",
690
                ],
691
            ],
692
            [
693
                Schema::TYPE_STRING . '(32) CHECK (value LIKE \'test%\')',
694
                $this->string(32)->check('value LIKE \'test%\''),
695
                [
696
                    'pgsql' => 'varchar(32) CHECK (value LIKE \'test%\')',
697
                    'oci' => 'VARCHAR2(32) CHECK (value LIKE \'test%\')',
698
                ],
699
            ],
700
            [
701
                Schema::TYPE_STRING . '(32)',
702
                $this->string(32),
703
                [
704
                    'mysql' => 'varchar(32)',
705
                    'pgsql' => 'varchar(32)',
706
                    'sqlite' => 'varchar(32)',
707
                    'oci' => 'VARCHAR2(32)',
708
                    'sqlsrv' => 'nvarchar(32)',
709
                ],
710
            ],
711
            [
712
                Schema::TYPE_STRING,
713
                $this->string(),
714
                [
715
                    'mysql' => 'varchar(255)',
716
                    'pgsql' => 'varchar(255)',
717
                    'sqlite' => 'varchar(255)',
718
                    'oci' => 'VARCHAR2(255)',
719
                    'sqlsrv' => 'nvarchar(255)',
720
                ],
721
            ],
722
            [
723
                Schema::TYPE_TEXT . " CHECK (value LIKE 'test%')",
724
                $this->text()->check("value LIKE 'test%'"),
0 ignored issues
show
Bug introduced by
It seems like text() 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

724
                $this->/** @scrutinizer ignore-call */ 
725
                       text()->check("value LIKE 'test%'"),
Loading history...
725
                [
726
                    'mysql' => "text CHECK (value LIKE 'test%')",
727
                    'sqlite' => "text CHECK (value LIKE 'test%')",
728
                    'sqlsrv' => "nvarchar(max) CHECK (value LIKE 'test%')",
729
                ],
730
            ],
731
            [
732
                Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')',
733
                $this->text()->check('value LIKE \'test%\''),
734
                [
735
                    'pgsql' => 'text CHECK (value LIKE \'test%\')',
736
                    'oci' => 'CLOB CHECK (value LIKE \'test%\')',
737
                ],
738
            ],
739
            [
740
                Schema::TYPE_TEXT . ' NOT NULL',
741
                $this->text()->notNull(),
742
                [
743
                    'mysql' => 'text NOT NULL',
744
                    'pgsql' => 'text NOT NULL',
745
                    'sqlite' => 'text NOT NULL',
746
                    'oci' => 'CLOB NOT NULL',
747
                    'sqlsrv' => 'nvarchar(max) NOT NULL',
748
                ],
749
            ],
750
            [
751
                Schema::TYPE_TEXT . " CHECK (value LIKE 'test%')",
752
                $this->text()->check("value LIKE 'test%'"),
753
                [
754
                    'mysql' => "text CHECK (value LIKE 'test%')",
755
                    'sqlite' => "text CHECK (value LIKE 'test%')",
756
                    'sqlsrv' => "nvarchar(max) CHECK (value LIKE 'test%')",
757
                ],
758
                Schema::TYPE_TEXT . " CHECK (value LIKE 'test%')",
759
            ],
760
            [
761
                Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')',
762
                $this->text()->check('value LIKE \'test%\''),
763
                [
764
                    'pgsql' => 'text CHECK (value LIKE \'test%\')',
765
                    'oci' => 'CLOB CHECK (value LIKE \'test%\')',
766
                ],
767
                Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')',
768
            ],
769
            [
770
                Schema::TYPE_TEXT . ' NOT NULL',
771
                $this->text()->notNull(),
772
                [
773
                    'mysql' => 'text NOT NULL',
774
                    'pgsql' => 'text NOT NULL',
775
                    'sqlite' => 'text NOT NULL',
776
                    'oci' => 'CLOB NOT NULL',
777
                    'sqlsrv' => 'nvarchar(max) NOT NULL',
778
                ],
779
                Schema::TYPE_TEXT . ' NOT NULL',
780
            ],
781
            [
782
                Schema::TYPE_TEXT,
783
                $this->text(),
784
                [
785
                    'mysql' => 'text',
786
                    'pgsql' => 'text',
787
                    'sqlite' => 'text',
788
                    'oci' => 'CLOB',
789
                    'sqlsrv' => 'nvarchar(max)',
790
                ],
791
                Schema::TYPE_TEXT,
792
            ],
793
            [
794
                Schema::TYPE_TEXT,
795
                $this->text(),
796
                [
797
                    'mysql' => 'text',
798
                    'pgsql' => 'text',
799
                    'sqlite' => 'text',
800
                    'oci' => 'CLOB',
801
                    'sqlsrv' => 'nvarchar(max)',
802
                ],
803
            ],
804
            [
805
                Schema::TYPE_TIME . ' NOT NULL',
806
                $this->time()->notNull(),
0 ignored issues
show
Bug introduced by
It seems like time() 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

806
                $this->/** @scrutinizer ignore-call */ 
807
                       time()->notNull(),
Loading history...
807
                [
808
                    'mysql' => version_compare($version, '5.6.4', '>=') ? 'time(0) NOT NULL' : 'time NOT NULL',
809
                    'pgsql' => 'time(0) NOT NULL',
810
                    'sqlite' => 'time NOT NULL',
811
                    'oci' => 'TIMESTAMP NOT NULL',
812
                    'sqlsrv' => 'time NOT NULL',
813
                ],
814
            ],
815
            [
816
                Schema::TYPE_TIME,
817
                $this->time(),
818
                [
819
                    'mysql' => version_compare($version, '5.6.4', '>=') ? 'time(0)' : 'time',
820
                    'pgsql' => 'time(0)',
821
                    'sqlite' => 'time',
822
                    'oci' => 'TIMESTAMP',
823
                    'sqlsrv' => 'time',
824
                ],
825
            ],
826
            [
827
                Schema::TYPE_TIMESTAMP . ' NOT NULL',
828
                $this->timestamp()->notNull(),
0 ignored issues
show
Bug introduced by
It seems like timestamp() 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

828
                $this->/** @scrutinizer ignore-call */ 
829
                       timestamp()->notNull(),
Loading history...
829
                [
830
                    'mysql' => version_compare($version, '5.6.4', '>=') ? 'timestamp(0) NOT NULL'
831
                        : 'timestamp NOT NULL',
832
                    'pgsql' => 'timestamp(0) NOT NULL',
833
                    'sqlite' => 'timestamp NOT NULL',
834
                    'oci' => 'TIMESTAMP NOT NULL',
835
                    'sqlsrv' => 'datetime NOT NULL',
836
                ],
837
            ],
838
            [
839
                Schema::TYPE_TIMESTAMP . ' NULL DEFAULT NULL',
840
                $this->timestamp()->defaultValue(null),
841
                [
842
                    'mysql' => version_compare($version, '5.6.4', '>=') ? 'timestamp(0) NULL DEFAULT NULL'
843
                        : 'timestamp NULL DEFAULT NULL',
844
                    'pgsql' => 'timestamp(0) NULL DEFAULT NULL',
845
                    'sqlite' => 'timestamp NULL DEFAULT NULL',
846
                    'sqlsrv' => 'datetime NULL DEFAULT NULL',
847
                ],
848
            ],
849
            [
850
                Schema::TYPE_TIMESTAMP . '(4)',
851
                $this->timestamp(4),
852
                [
853
                    'pgsql' => 'timestamp(4)',
854
                ],
855
            ],
856
            [
857
                Schema::TYPE_TIMESTAMP,
858
                $this->timestamp(),
859
                [
860
                    /**
861
                     * MySQL has its own TIMESTAMP test realization.
862
                     *
863
                     * {@see QueryBuilderTest::columnTypes()}
864
                     */
865
                    'pgsql' => 'timestamp(0)',
866
                    'sqlite' => 'timestamp',
867
                    'oci' => 'TIMESTAMP',
868
                    'sqlsrv' => 'datetime',
869
                ],
870
            ],
871
            [
872
                Schema::TYPE_UPK,
873
                $this->primaryKey()->unsigned(),
874
                [
875
                    'mysql' => 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
876
                    'pgsql' => 'serial NOT NULL PRIMARY KEY',
877
                    'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
878
                ],
879
            ],
880
            [
881
                Schema::TYPE_UBIGPK,
882
                $this->bigPrimaryKey()->unsigned(),
883
                [
884
                    'mysql' => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
885
                    'pgsql' => 'bigserial NOT NULL PRIMARY KEY',
886
                    'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
887
                ],
888
            ],
889
            [
890
                Schema::TYPE_INTEGER . " COMMENT 'test comment'",
891
                $this->integer()->comment('test comment'),
892
                [
893
                    'mysql' => "int(11) COMMENT 'test comment'",
894
                    'sqlsrv' => 'int',
895
                ],
896
                [
897
                    'sqlsrv' => 'integer',
898
                ],
899
            ],
900
            [
901
                Schema::TYPE_PK . " COMMENT 'test comment'",
902
                $this->primaryKey()->comment('test comment'),
903
                [
904
                    'mysql' => "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test comment'",
905
                    'sqlsrv' => 'int IDENTITY PRIMARY KEY',
906
                ],
907
                [
908
                    'sqlsrv' => 'pk',
909
                ],
910
            ],
911
            [
912
                Schema::TYPE_PK . ' FIRST',
913
                $this->primaryKey()->first(),
914
                [
915
                    'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST',
916
                    'sqlsrv' => 'int IDENTITY PRIMARY KEY',
917
                ],
918
                [
919
                    'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY FIRST',
920
                    'sqlsrv' => 'pk',
921
                ],
922
            ],
923
            [
924
                Schema::TYPE_INTEGER . ' FIRST',
925
                $this->integer()->first(),
926
                [
927
                    'mysql' => 'int(11) FIRST',
928
                    'sqlsrv' => 'int',
929
                ],
930
                [
931
                    'oci' => 'NUMBER(10) FIRST',
932
                    'pgsql' => 'integer',
933
                    'sqlsrv' => 'integer',
934
                ],
935
            ],
936
            [
937
                Schema::TYPE_STRING . ' FIRST',
938
                $this->string()->first(),
939
                [
940
                    'mysql' => 'varchar(255) FIRST',
941
                    'sqlsrv' => 'nvarchar(255)',
942
                ],
943
                [
944
                    'oci' => 'VARCHAR2(255) FIRST',
945
                    'sqlsrv' => 'string',
946
                ],
947
            ],
948
            [
949
                Schema::TYPE_INTEGER . ' NOT NULL FIRST',
950
                $this->integer()->append('NOT NULL')->first(),
951
                [
952
                    'mysql' => 'int(11) NOT NULL FIRST',
953
                    'sqlsrv' => 'int NOT NULL',
954
                ],
955
                [
956
                    'oci' => 'NUMBER(10) NOT NULL FIRST',
957
                    'sqlsrv' => 'integer NOT NULL',
958
                ],
959
            ],
960
            [
961
                Schema::TYPE_STRING . ' NOT NULL FIRST',
962
                $this->string()->append('NOT NULL')->first(),
963
                [
964
                    'mysql' => 'varchar(255) NOT NULL FIRST',
965
                    'sqlsrv' => 'nvarchar(255) NOT NULL',
966
                ],
967
                [
968
                    'oci' => 'VARCHAR2(255) NOT NULL FIRST',
969
                    'sqlsrv' => 'string NOT NULL',
970
                ],
971
            ],
972
            [
973
                Schema::TYPE_JSON,
974
                $this->json(),
0 ignored issues
show
Bug introduced by
It seems like json() 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

974
                $this->/** @scrutinizer ignore-call */ 
975
                       json(),
Loading history...
975
                [
976
                    'pgsql' => 'jsonb',
977
                ],
978
            ],
979
        ];
980
981
        $driverName = $this->getConnection()->getDriver()->getDriverName();
0 ignored issues
show
Bug introduced by
It seems like getConnection() 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

981
        $driverName = $this->/** @scrutinizer ignore-call */ getConnection()->getDriver()->getDriverName();
Loading history...
982
        foreach ($items as $i => $item) {
983
            if (array_key_exists($driverName, $item[2])) {
984
                $item[2] = $item[2][$driverName];
985
                $items[$i] = $item;
986
            } else {
987
                unset($items[$i]);
988
            }
989
        }
990
991
        return array_values($items);
992
    }
993
}
994