1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of FlexPHP. |
4
|
|
|
* |
5
|
|
|
* (c) Freddie Gar <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace FlexPHP\Schema\Traits; |
11
|
|
|
|
12
|
|
|
use FlexPHP\Schema\SchemaAttributeInterface; |
13
|
|
|
|
14
|
|
|
trait AttributeHelperTrait |
15
|
|
|
{ |
16
|
50 |
|
private function isInt(SchemaAttributeInterface $property): bool |
17
|
|
|
{ |
18
|
50 |
|
return \in_array($property->dataType(), ['smallint', 'integer', 'bigint']); |
19
|
|
|
} |
20
|
|
|
|
21
|
227 |
|
private function isDate(SchemaAttributeInterface $property): bool |
22
|
|
|
{ |
23
|
227 |
|
return \strpos($property->typeHint(), '\Date') !== false; |
24
|
|
|
} |
25
|
|
|
|
26
|
35 |
|
private function isArray(SchemaAttributeInterface $property): bool |
27
|
|
|
{ |
28
|
35 |
|
return \in_array($property->dataType(), ['array', 'simple_array', 'json']); |
29
|
|
|
} |
30
|
|
|
|
31
|
238 |
|
private function isNumeric(SchemaAttributeInterface $property): bool |
32
|
|
|
{ |
33
|
238 |
|
return \in_array($property->dataType(), ['smallint', 'integer', 'bigint', 'double', 'float']); |
34
|
|
|
} |
35
|
|
|
|
36
|
45 |
|
private function isText(SchemaAttributeInterface $property): bool |
37
|
|
|
{ |
38
|
45 |
|
return $property->dataType() === 'text'; |
39
|
|
|
} |
40
|
|
|
|
41
|
44 |
|
private function isObject(SchemaAttributeInterface $property): bool |
42
|
|
|
{ |
43
|
44 |
|
return $property->dataType() === 'object'; |
44
|
|
|
} |
45
|
|
|
|
46
|
228 |
|
private function isString(SchemaAttributeInterface $property): bool |
47
|
|
|
{ |
48
|
228 |
|
return $property->dataType() !== 'bigint' && $property->typeHint() === 'string'; |
49
|
|
|
} |
50
|
|
|
|
51
|
194 |
|
private function isBinary(SchemaAttributeInterface $property): bool |
52
|
|
|
{ |
53
|
194 |
|
return \in_array($property->dataType(), ['binary', 'bool', 'boolean', 'blob']); |
54
|
|
|
} |
55
|
|
|
|
56
|
142 |
|
private function hasLength(SchemaAttributeInterface $property): bool |
57
|
|
|
{ |
58
|
142 |
|
return $property->minLength() !== null || $property->maxLength() !== null; |
59
|
|
|
} |
60
|
|
|
|
61
|
159 |
|
private function hasSize(SchemaAttributeInterface $property): bool |
62
|
|
|
{ |
63
|
159 |
|
return $property->min() !== null || $property->max() !== null; |
64
|
|
|
} |
65
|
|
|
|
66
|
70 |
|
private function hasCheck(SchemaAttributeInterface $property): bool |
67
|
|
|
{ |
68
|
70 |
|
return $property->minCheck() !== null || $property->maxCheck() !== null; |
69
|
|
|
} |
70
|
|
|
|
71
|
73 |
|
private function hasSizing(SchemaAttributeInterface $property): bool |
72
|
|
|
{ |
73
|
73 |
|
return $this->hasSize($property) || $this->hasLength($property) || $this->hasCheck($property); |
74
|
|
|
} |
75
|
|
|
|
76
|
220 |
|
private function hasFormat(SchemaAttributeInterface $property): bool |
77
|
|
|
{ |
78
|
220 |
|
return (bool)$property->format(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|