Total Complexity | 53 |
Total Lines | 865 |
Duplicated Lines | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
Complex classes like SchemaAttributeTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SchemaAttributeTest, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
15 | class SchemaAttributeTest extends TestCase |
||
16 | { |
||
17 | public function testItSchemaAttributeWithInvalidNamePropertiesThrowException(): void |
||
18 | { |
||
19 | $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class); |
||
20 | $this->expectExceptionMessage('Name:'); |
||
21 | |||
22 | new SchemaAttribute('', 'string'); |
||
23 | } |
||
24 | |||
25 | public function testItSchemaAttributeWithInvalidDataTypePropertiesThrowException(): void |
||
26 | { |
||
27 | $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class); |
||
28 | $this->expectExceptionMessage('DataType:'); |
||
29 | |||
30 | new SchemaAttribute('foo', 'bar'); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @dataProvider getConstraintLogicError |
||
35 | */ |
||
36 | public function testItSchemaAttributeConstraintLogicError(string $dataType, string $constraints): void |
||
37 | { |
||
38 | $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class); |
||
39 | $this->expectExceptionMessage('Logic:'); |
||
40 | |||
41 | new SchemaAttribute('foo', $dataType, $constraints); |
||
42 | } |
||
43 | |||
44 | public function testItSchemaAttributeWithRequiredPropertiesSetValues(): void |
||
45 | { |
||
46 | $name = 'foo'; |
||
47 | $dataType = 'string'; |
||
48 | |||
49 | $schemaAttribute = new SchemaAttribute($name, $dataType); |
||
50 | |||
51 | $this->assertEquals($name, $schemaAttribute->name()); |
||
52 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @dataProvider getRequiredConstraint |
||
57 | * |
||
58 | * @param mixed $constraint |
||
59 | * @param mixed $expected |
||
60 | */ |
||
61 | public function testItSchemaAttributeRequiredConstraints($constraint, $expected): void |
||
62 | { |
||
63 | $name = 'foo'; |
||
64 | $dataType = 'string'; |
||
65 | |||
66 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
67 | |||
68 | $this->assertEquals($name, $schemaAttribute->name()); |
||
69 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
70 | $this->assertSame($expected, $schemaAttribute->isRequired()); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @dataProvider getMinLengthConstraint |
||
75 | * |
||
76 | * @param mixed $constraint |
||
77 | * @param mixed $expected |
||
78 | */ |
||
79 | public function testItSchemaAttributeMinLengthConstraints($constraint, $expected): void |
||
80 | { |
||
81 | $name = 'foo'; |
||
82 | $dataType = 'string'; |
||
83 | |||
84 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
85 | |||
86 | $this->assertEquals($name, $schemaAttribute->name()); |
||
87 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
88 | $this->assertSame($expected, $schemaAttribute->minLength()); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @dataProvider getMinConstraint |
||
93 | * |
||
94 | * @param mixed $constraint |
||
95 | * @param mixed $expected |
||
96 | */ |
||
97 | public function testItSchemaAttributeMinConstraints($constraint, $expected): void |
||
98 | { |
||
99 | $name = 'min'; |
||
100 | $dataType = 'integer'; |
||
101 | |||
102 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
103 | |||
104 | $this->assertEquals($name, $schemaAttribute->name()); |
||
105 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
106 | $this->assertSame($expected, $schemaAttribute->min()); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @dataProvider getMaxLengthConstraint |
||
111 | * |
||
112 | * @param mixed $constraint |
||
113 | * @param mixed $expected |
||
114 | */ |
||
115 | public function testItSchemaAttributeMaxLengthConstraints($constraint, $expected): void |
||
116 | { |
||
117 | $name = 'minLength'; |
||
118 | $dataType = 'string'; |
||
119 | |||
120 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
121 | |||
122 | $this->assertEquals($name, $schemaAttribute->name()); |
||
123 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
124 | $this->assertSame($expected, $schemaAttribute->maxLength()); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @dataProvider getMaxConstraint |
||
129 | * |
||
130 | * @param mixed $constraint |
||
131 | * @param mixed $expected |
||
132 | */ |
||
133 | public function testItSchemaAttributeMaxConstraints($constraint, $expected): void |
||
134 | { |
||
135 | $name = 'max'; |
||
136 | $dataType = 'integer'; |
||
137 | |||
138 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
139 | |||
140 | $this->assertEquals($name, $schemaAttribute->name()); |
||
141 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
142 | $this->assertSame($expected, $schemaAttribute->max()); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @dataProvider getMinCheckConstraint |
||
147 | * |
||
148 | * @param mixed $constraint |
||
149 | * @param mixed $expected |
||
150 | */ |
||
151 | public function testItSchemaAttributeMinCheckConstraints($constraint, $expected): void |
||
152 | { |
||
153 | $name = 'minCheck'; |
||
154 | $dataType = 'integer'; |
||
155 | |||
156 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
157 | |||
158 | $this->assertEquals($name, $schemaAttribute->name()); |
||
159 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
160 | $this->assertSame($expected, $schemaAttribute->minCheck()); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @dataProvider getMaxCheckConstraint |
||
165 | * |
||
166 | * @param mixed $constraint |
||
167 | * @param mixed $expected |
||
168 | */ |
||
169 | public function testItSchemaAttributeMaxCheckConstraints($constraint, $expected): void |
||
170 | { |
||
171 | $name = 'maxCheck'; |
||
172 | $dataType = 'integer'; |
||
173 | |||
174 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
175 | |||
176 | $this->assertEquals($name, $schemaAttribute->name()); |
||
177 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
178 | $this->assertSame($expected, $schemaAttribute->maxCheck()); |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @dataProvider getCheckConstraint |
||
183 | * |
||
184 | * @param mixed $constraint |
||
185 | * @param mixed $expectedMin |
||
186 | * @param mixed $expectedMax |
||
187 | */ |
||
188 | public function testItSchemaAttributeCheckConstraints($constraint, $expectedMin, $expectedMax): void |
||
189 | { |
||
190 | $name = 'check'; |
||
191 | $dataType = 'integer'; |
||
192 | |||
193 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
194 | |||
195 | $this->assertEquals($name, $schemaAttribute->name()); |
||
196 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
197 | $this->assertSame($expectedMin, $schemaAttribute->minCheck()); |
||
198 | $this->assertSame($expectedMax, $schemaAttribute->maxCheck()); |
||
199 | } |
||
200 | |||
201 | /** |
||
202 | * @dataProvider getLengthConstraint |
||
203 | * |
||
204 | * @param mixed $constraint |
||
205 | * @param mixed $expectedMin |
||
206 | * @param mixed $expectedMax |
||
207 | */ |
||
208 | public function testItSchemaAttributeLengthConstraints($constraint, $expectedMin, $expectedMax): void |
||
209 | { |
||
210 | $name = 'length'; |
||
211 | $dataType = 'string'; |
||
212 | |||
213 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
214 | |||
215 | $this->assertEquals($name, $schemaAttribute->name()); |
||
216 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
217 | $this->assertSame($expectedMin, $schemaAttribute->minLength()); |
||
218 | $this->assertSame($expectedMax, $schemaAttribute->maxLength()); |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * @dataProvider getEqualToConstraint |
||
223 | * |
||
224 | * @param mixed $constraint |
||
225 | * @param mixed $expected |
||
226 | */ |
||
227 | public function testItSchemaAttributeEqualToConstraints($constraint, $expected): void |
||
228 | { |
||
229 | $name = 'equalTo'; |
||
230 | $dataType = 'string'; |
||
231 | |||
232 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
233 | |||
234 | $this->assertEquals($name, $schemaAttribute->name()); |
||
235 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
236 | $this->assertSame($expected, $schemaAttribute->equalTo()); |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @dataProvider getTypeConstraint |
||
241 | * |
||
242 | * @param mixed $constraint |
||
243 | * @param mixed $expected |
||
244 | */ |
||
245 | public function testItSchemaAttributeTypeConstraints($constraint, $expected): void |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * @dataProvider getPkConstraint |
||
259 | * |
||
260 | * @param mixed $constraint |
||
261 | * @param mixed $expected |
||
262 | */ |
||
263 | public function testItSchemaAttributePkConstraints($constraint, $expected): void |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * @dataProvider getAiConstraint |
||
277 | * |
||
278 | * @param mixed $constraint |
||
279 | * @param mixed $expected |
||
280 | */ |
||
281 | public function testItSchemaAttributeAiConstraints($constraint, $expected): void |
||
282 | { |
||
283 | $name = 'foo'; |
||
284 | $dataType = 'integer'; |
||
285 | |||
286 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
287 | |||
288 | $this->assertEquals($name, $schemaAttribute->name()); |
||
289 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
290 | $this->assertSame($expected, $schemaAttribute->isAi()); |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * @dataProvider getCaConstraint |
||
295 | * |
||
296 | * @param mixed $constraint |
||
297 | * @param mixed $expected |
||
298 | */ |
||
299 | public function testItSchemaAttributeCaConstraints($constraint, $expected): void |
||
300 | { |
||
301 | $name = 'foo'; |
||
302 | $dataType = 'datetime'; |
||
303 | |||
304 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
305 | |||
306 | $this->assertEquals($name, $schemaAttribute->name()); |
||
307 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
308 | $this->assertSame($expected, $schemaAttribute->isCa()); |
||
309 | $this->assertSame($expected, $schemaAttribute->isBlame()); |
||
310 | $this->assertSame($expected, $schemaAttribute->isBlameAt()); |
||
311 | $this->assertSame(false, $schemaAttribute->isBlameBy()); |
||
312 | } |
||
313 | |||
314 | /** |
||
315 | * @dataProvider getUaConstraint |
||
316 | * |
||
317 | * @param mixed $constraint |
||
318 | * @param mixed $expected |
||
319 | */ |
||
320 | public function testItSchemaAttributeUaConstraints($constraint, $expected): void |
||
321 | { |
||
322 | $name = 'foo'; |
||
323 | $dataType = 'datetime'; |
||
324 | |||
325 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
326 | |||
327 | $this->assertEquals($name, $schemaAttribute->name()); |
||
328 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
329 | $this->assertSame($expected, $schemaAttribute->isUa()); |
||
330 | $this->assertSame($expected, $schemaAttribute->isBlame()); |
||
331 | $this->assertSame($expected, $schemaAttribute->isBlameAt()); |
||
332 | $this->assertSame(false, $schemaAttribute->isBlameBy()); |
||
333 | } |
||
334 | |||
335 | /** |
||
336 | * @dataProvider getCbConstraint |
||
337 | * |
||
338 | * @param mixed $constraint |
||
339 | * @param mixed $expected |
||
340 | */ |
||
341 | public function testItSchemaAttributeCbConstraints($constraint, $expected): void |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * @dataProvider getUbConstraint |
||
358 | * |
||
359 | * @param mixed $constraint |
||
360 | * @param mixed $expected |
||
361 | */ |
||
362 | public function testItSchemaAttributeUbConstraints($constraint, $expected): void |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * @dataProvider getFilterConstraint |
||
379 | * |
||
380 | * @param mixed $constraint |
||
381 | * @param mixed $expected |
||
382 | */ |
||
383 | public function testItSchemaAttributeFilterConstraints($constraint, $expected): void |
||
384 | { |
||
385 | $name = 'foo'; |
||
386 | $dataType = 'integer'; |
||
387 | |||
388 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
389 | |||
390 | $this->assertEquals($name, $schemaAttribute->name()); |
||
391 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
392 | $this->assertSame($expected, $schemaAttribute->filter()); |
||
393 | } |
||
394 | |||
395 | /** |
||
396 | * @dataProvider getFormatConstraint |
||
397 | */ |
||
398 | public function testItSchemaAttributeFormatConstraints(string $dataType, string $constraint, ?string $expected): void |
||
399 | { |
||
400 | $name = 'foo'; |
||
401 | |||
402 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
403 | |||
404 | $this->assertEquals($name, $schemaAttribute->name()); |
||
405 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
406 | $this->assertSame($expected, $schemaAttribute->format()); |
||
407 | } |
||
408 | |||
409 | /** |
||
410 | * @dataProvider getTrimConstraint |
||
411 | * |
||
412 | * @param mixed $constraint |
||
413 | */ |
||
414 | public function testItSchemaAttributeTrimConstraints($constraint, bool $expected): void |
||
415 | { |
||
416 | $name = 'foo'; |
||
417 | $dataType = 'string'; |
||
418 | |||
419 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
420 | |||
421 | $this->assertEquals($name, $schemaAttribute->name()); |
||
422 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
423 | $this->assertSame($expected, $schemaAttribute->trim()); |
||
424 | } |
||
425 | |||
426 | /** |
||
427 | * @dataProvider getFcharsConstraint |
||
428 | * |
||
429 | * @param mixed $constraint |
||
430 | */ |
||
431 | public function testItSchemaAttributeFcharsConstraints(string $constraint, int $expected): void |
||
432 | { |
||
433 | $name = 'foo'; |
||
434 | $dataType = 'string'; |
||
435 | |||
436 | if (!empty($constraint)) { |
||
437 | $constraint = 'fk:fkTable,fkName|' . $constraint; |
||
438 | } |
||
439 | |||
440 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
441 | |||
442 | $this->assertEquals($name, $schemaAttribute->name()); |
||
443 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
444 | $this->assertSame($expected, $schemaAttribute->fchars()); |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * @dataProvider getFkConstraint |
||
449 | * |
||
450 | * @param mixed $constraint |
||
451 | * @param mixed $fkTable |
||
452 | * @param mixed $fkId |
||
453 | * @param mixed $fkName |
||
454 | */ |
||
455 | public function testItSchemaAttributeFkConstraints($constraint, $fkTable, $fkId, $fkName): void |
||
456 | { |
||
457 | $name = 'foreing'; |
||
458 | $dataType = 'integer'; |
||
459 | |||
460 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
461 | |||
462 | $this->assertEquals($name, $schemaAttribute->name()); |
||
463 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
464 | $this->assertEquals('int', $schemaAttribute->typeHint()); |
||
465 | $this->assertTrue($schemaAttribute->isFk()); |
||
466 | $this->assertSame($fkTable, $schemaAttribute->fkTable()); |
||
467 | $this->assertSame($fkId, $schemaAttribute->fkId()); |
||
468 | $this->assertSame($fkName, $schemaAttribute->fkName()); |
||
469 | } |
||
470 | |||
471 | public function testItSchemaAttributeConstraintsAsString(): void |
||
472 | { |
||
473 | $name = 'foo'; |
||
474 | $dataType = 'string'; |
||
475 | $constraints = 'required|minlength:8|maxlength:10|mincheck:3|maxcheck:4|equalto:#bar|type:number'; |
||
476 | |||
477 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints); |
||
478 | |||
479 | $this->assertEquals($name, $schemaAttribute->name()); |
||
480 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
481 | $this->assertEquals('string', $schemaAttribute->typeHint()); |
||
482 | $this->assertIsArray($schemaAttribute->constraints()); |
||
483 | $this->assertSame(true, $schemaAttribute->isRequired()); |
||
484 | $this->assertNull($schemaAttribute->min()); |
||
485 | $this->assertSame(8, $schemaAttribute->minLength()); |
||
486 | $this->assertSame(3, $schemaAttribute->minCheck()); |
||
487 | $this->assertNull($schemaAttribute->max()); |
||
488 | $this->assertSame(10, $schemaAttribute->maxLength()); |
||
489 | $this->assertSame(4, $schemaAttribute->maxCheck()); |
||
490 | $this->assertSame('#bar', $schemaAttribute->equalTo()); |
||
491 | $this->assertSame('number', $schemaAttribute->type()); |
||
492 | $this->assertFalse($schemaAttribute->isPk()); |
||
493 | $this->assertFalse($schemaAttribute->isAi()); |
||
494 | $this->assertFalse($schemaAttribute->isFk()); |
||
495 | $this->assertNull($schemaAttribute->fkTable()); |
||
496 | $this->assertNull($schemaAttribute->fkId()); |
||
497 | $this->assertNull($schemaAttribute->fkName()); |
||
498 | } |
||
499 | |||
500 | public function testItSchemaAttributeConstraintsAsArray(): void |
||
501 | { |
||
502 | $name = 'foo'; |
||
503 | $dataType = 'integer'; |
||
504 | $constraints = [ |
||
505 | 'required', |
||
506 | 'equalto' => '#id', |
||
507 | 'type' => 'text', |
||
508 | 'pk' => true, |
||
509 | 'ai' => true, |
||
510 | ]; |
||
511 | |||
512 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints); |
||
513 | |||
514 | $this->assertEquals($name, $schemaAttribute->name()); |
||
515 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
516 | $this->assertEquals('int', $schemaAttribute->typeHint()); |
||
517 | $this->assertIsArray($schemaAttribute->constraints()); |
||
518 | $this->assertSame(true, $schemaAttribute->isRequired()); |
||
519 | $this->assertNull($schemaAttribute->min()); |
||
520 | $this->assertNull($schemaAttribute->minLength()); |
||
521 | $this->assertNull($schemaAttribute->minCheck()); |
||
522 | $this->assertNull($schemaAttribute->max()); |
||
523 | $this->assertNull($schemaAttribute->maxLength()); |
||
524 | $this->assertNull($schemaAttribute->maxCheck()); |
||
525 | $this->assertSame('#id', $schemaAttribute->equalTo()); |
||
526 | $this->assertSame('text', $schemaAttribute->type()); |
||
527 | $this->assertTrue($schemaAttribute->isPk()); |
||
528 | $this->assertTrue($schemaAttribute->isAi()); |
||
529 | $this->assertFalse($schemaAttribute->isFk()); |
||
530 | } |
||
531 | |||
532 | public function testItSchemaAttributeConstraintsAsArrayCast(): void |
||
533 | { |
||
534 | $name = 'foo'; |
||
535 | $dataType = 'datetime'; |
||
536 | $constraints = [ |
||
537 | 'required', |
||
538 | 'equalto' => '#bar', |
||
539 | 'type' => 'number', |
||
540 | ]; |
||
541 | |||
542 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints); |
||
543 | |||
544 | $this->assertEquals($name, $schemaAttribute->name()); |
||
545 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
546 | $this->assertEquals('\DateTime', $schemaAttribute->typeHint()); |
||
547 | $this->assertIsArray($schemaAttribute->constraints()); |
||
548 | $this->assertSame(true, $schemaAttribute->isRequired()); |
||
549 | $this->assertNull($schemaAttribute->min()); |
||
550 | $this->assertNull($schemaAttribute->minLength()); |
||
551 | $this->assertNull($schemaAttribute->minCheck()); |
||
552 | $this->assertNull($schemaAttribute->max()); |
||
553 | $this->assertNull($schemaAttribute->maxLength()); |
||
554 | $this->assertNull($schemaAttribute->maxCheck()); |
||
555 | $this->assertSame('#bar', $schemaAttribute->equalTo()); |
||
556 | $this->assertSame('number', $schemaAttribute->type()); |
||
557 | } |
||
558 | |||
559 | public function getRequiredConstraint(): array |
||
560 | { |
||
561 | return [ |
||
562 | ['', false], |
||
563 | ['required', true], |
||
564 | ['required:true', true], |
||
565 | ['required:false', false], |
||
566 | [['required'], true], |
||
567 | [['required' => true], true], |
||
568 | [['required' => false], false], |
||
569 | ]; |
||
570 | } |
||
571 | |||
572 | public function getMinLengthConstraint(): array |
||
573 | { |
||
574 | return [ |
||
575 | ['', null], |
||
576 | ['minlength:8', 8], |
||
577 | [['minlength' => 8], 8], |
||
578 | [['minlength' => '8'], 8], |
||
579 | ]; |
||
580 | } |
||
581 | |||
582 | public function getMinConstraint(): array |
||
583 | { |
||
584 | return [ |
||
585 | ['', null], |
||
586 | ['min:8', 8], |
||
587 | [['min' => 8], 8], |
||
588 | [['min' => '8'], 8], |
||
589 | ]; |
||
590 | } |
||
591 | |||
592 | public function getMaxLengthConstraint(): array |
||
593 | { |
||
594 | return [ |
||
595 | ['', null], |
||
596 | ['maxlength:10', 10], |
||
597 | [['maxlength' => 10], 10], |
||
598 | [['maxlength' => '10'], 10], |
||
599 | ]; |
||
600 | } |
||
601 | |||
602 | public function getMaxConstraint(): array |
||
603 | { |
||
604 | return [ |
||
605 | ['', null], |
||
606 | ['max:100', 100], |
||
607 | [['max' => 100], 100], |
||
608 | [['max' => '100'], 100], |
||
609 | ]; |
||
610 | } |
||
611 | |||
612 | public function getMinCheckConstraint(): array |
||
613 | { |
||
614 | return [ |
||
615 | ['', null], |
||
616 | ['mincheck:3', 3], |
||
617 | [['mincheck' => 3], 3], |
||
618 | [['mincheck' => '3'], 3], |
||
619 | ]; |
||
620 | } |
||
621 | |||
622 | public function getMaxCheckConstraint(): array |
||
623 | { |
||
624 | return [ |
||
625 | ['', null], |
||
626 | ['maxcheck:4', 4], |
||
627 | [['maxcheck' => 4], 4], |
||
628 | [['maxcheck' => '4'], 4], |
||
629 | ]; |
||
630 | } |
||
631 | |||
632 | public function getCheckConstraint(): array |
||
641 | ]; |
||
642 | } |
||
643 | |||
644 | public function getLengthConstraint(): array |
||
645 | { |
||
646 | return [ |
||
647 | ['', null, null], |
||
648 | ['length:30,40', 30, 40], |
||
649 | [['length' => [ |
||
650 | 'min' => 5, |
||
651 | 'max' => 60, |
||
652 | ]], 5, 60], |
||
653 | ]; |
||
654 | } |
||
655 | |||
656 | public function getEqualToConstraint(): array |
||
657 | { |
||
658 | return [ |
||
659 | ['', null], |
||
660 | ['equalto:#foo', '#foo'], |
||
661 | [['equalto' => '.foo'], '.foo'], |
||
662 | ]; |
||
663 | } |
||
664 | |||
665 | public function getTypeConstraint(): array |
||
666 | { |
||
667 | return [ |
||
668 | ['', null], |
||
669 | ['type:number', 'number'], |
||
670 | [['type' => 'text'], 'text'], |
||
671 | ]; |
||
672 | } |
||
673 | |||
674 | public function getPkConstraint(): array |
||
675 | { |
||
676 | return [ |
||
677 | ['', false], |
||
678 | ['required|pk', true], |
||
679 | ['required|pk:true', true], |
||
680 | ['required|pk:false', false], |
||
681 | [['required', 'pk'], true], |
||
682 | [['required', 'pk' => true], true], |
||
683 | [['required', 'pk' => false], false], |
||
684 | ]; |
||
685 | } |
||
686 | |||
687 | public function getAiConstraint(): array |
||
688 | { |
||
689 | return [ |
||
690 | ['', false], |
||
691 | ['required|pk|ai', true], |
||
692 | ['required|pk|ai:true', true], |
||
693 | // ['required|pk|ai:false', false], |
||
694 | [['required', 'pk', 'ai'], true], |
||
695 | [['required', 'pk', 'ai' => true], true], |
||
696 | // [['required', 'pk', 'ai' => false], false], |
||
697 | ]; |
||
698 | } |
||
699 | |||
700 | public function getCaConstraint(): array |
||
710 | ]; |
||
711 | } |
||
712 | |||
713 | public function getUaConstraint(): array |
||
714 | { |
||
715 | return [ |
||
716 | ['', false], |
||
717 | ['ua', true], |
||
718 | ['ua:true', true], |
||
719 | ['ua:false', false], |
||
720 | [['ua'], true], |
||
721 | [['ua' => true], true], |
||
722 | [['ua' => false], false], |
||
723 | ]; |
||
724 | } |
||
725 | |||
726 | public function getFkConstraint(): array |
||
727 | { |
||
728 | return [ |
||
729 | ['fk:table', 'table', 'id', 'name'], |
||
730 | ['fk:table2,username', 'table2', 'id', 'username'], |
||
731 | ['fk:table3,description,uuid', 'table3', 'uuid', 'description'], |
||
732 | [['fk' => 'table5'], 'table5', 'id', 'name'], |
||
733 | [['fk' => 'table6,username'], 'table6', 'id', 'username'], |
||
734 | [['fk' => 'table7,description,uuid'], 'table7', 'uuid', 'description'], |
||
735 | ]; |
||
736 | } |
||
737 | |||
738 | public function getCbConstraint(): array |
||
748 | ]; |
||
749 | } |
||
750 | |||
751 | public function getUbConstraint(): array |
||
752 | { |
||
753 | return [ |
||
754 | ['', false], |
||
755 | ['ub', true], |
||
756 | ['ub:true', true], |
||
757 | ['ub:false', false], |
||
758 | [['ub'], true], |
||
759 | [['ub' => true], true], |
||
760 | [['ub' => false], false], |
||
761 | ]; |
||
762 | } |
||
763 | |||
764 | public function getFilterConstraint(): array |
||
765 | { |
||
766 | return [ |
||
767 | ['', null], |
||
768 | ['filter:eq', 'eq'], |
||
769 | ['filter:nn', 'nn'], |
||
770 | ]; |
||
771 | } |
||
772 | |||
773 | public function getFormatConstraint(): array |
||
774 | { |
||
775 | return [ |
||
776 | ['string', '', null], |
||
777 | ['datetime', 'format:timeago', 'timeago'], |
||
778 | ['datetime', 'format:datetime', 'datetime'], |
||
779 | ['integer', 'format:money', 'money'], |
||
780 | ]; |
||
781 | } |
||
782 | |||
783 | public function getTrimConstraint(): array |
||
784 | { |
||
785 | return [ |
||
786 | ['', false], |
||
787 | ['trim', true], |
||
788 | ['trim:true', true], |
||
789 | ['trim:false', false], |
||
790 | [['trim'], true], |
||
791 | [['trim' => true], true], |
||
792 | [['trim' => false], false], |
||
793 | ]; |
||
794 | } |
||
795 | |||
796 | public function getFcharsConstraint(): array |
||
804 | ]; |
||
805 | } |
||
806 | |||
807 | public function getConstraintLogicError(): array |
||
880 | ]; |
||
881 | } |
||
882 | } |
||
883 |