Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
76.92% |
10 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ScalarType | |
76.92% |
10 / 13 |
|
66.67% |
2 / 3 |
8.79 | |
0.00% |
0 / 1 |
| toReflectionType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toDoctrineType | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| toJsonSchemaType | |
66.67% |
6 / 9 |
|
0.00% |
0 / 1 |
5.93 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Enums; |
| 3 | |
| 4 | use Apie\TypeConverter\ReflectionTypeFactory; |
| 5 | use ReflectionType; |
| 6 | use stdClass; |
| 7 | |
| 8 | enum ScalarType: string |
| 9 | { |
| 10 | case STRING = 'string'; |
| 11 | case FLOAT = 'float'; |
| 12 | case INTEGER = 'int'; |
| 13 | case NULLVALUE = 'null'; |
| 14 | case ARRAY = 'array'; |
| 15 | case BOOLEAN = 'bool'; |
| 16 | case MIXED = 'mixed'; |
| 17 | case STDCLASS = stdClass::class; |
| 18 | |
| 19 | public const PRIMITIVES = [self::STRING, self::FLOAT, self::INTEGER, self::BOOLEAN]; |
| 20 | |
| 21 | public function toReflectionType(): ReflectionType |
| 22 | { |
| 23 | return ReflectionTypeFactory::createReflectionType($this->value); |
| 24 | } |
| 25 | |
| 26 | public function toDoctrineType(): string |
| 27 | { |
| 28 | if ($this === self::INTEGER) { |
| 29 | return 'integer'; |
| 30 | } |
| 31 | return $this->value; |
| 32 | } |
| 33 | |
| 34 | public function toJsonSchemaType(): string |
| 35 | { |
| 36 | if ($this === self::INTEGER) { |
| 37 | return 'integer'; |
| 38 | } |
| 39 | if ($this === self::FLOAT) { |
| 40 | return 'number'; |
| 41 | } |
| 42 | if ($this === self::BOOLEAN) { |
| 43 | return 'boolean'; |
| 44 | } |
| 45 | if ($this === self::STDCLASS) { |
| 46 | return 'object'; |
| 47 | } |
| 48 | return $this->value; |
| 49 | } |
| 50 | } |