Total Complexity | 9 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
7 | class PhpPrimitive implements ValueObjectInterface |
||
8 | { |
||
9 | const STRING = 'STRING'; |
||
10 | |||
11 | const BOOL = 'BOOL'; |
||
12 | |||
13 | const INT = 'INT'; |
||
14 | |||
15 | const FLOAT = 'FLOAT'; |
||
16 | |||
17 | use StringEnumTrait; |
||
18 | |||
19 | /** |
||
20 | * Returns Schema used in OpenApi Spec. |
||
21 | * |
||
22 | * @return Schema |
||
23 | */ |
||
24 | public function getSchemaForFilter(): Schema |
||
25 | { |
||
26 | switch ($this->toNative()) { |
||
27 | case self::BOOL: |
||
28 | return new Schema(['type' => 'boolean']); |
||
29 | case self::INT: |
||
30 | return new Schema(['type' => 'number', 'format' => 'int32']); |
||
31 | case self::FLOAT: |
||
32 | return new Schema(['type' => 'number', 'format' => 'double']); |
||
33 | } |
||
34 | |||
35 | return new Schema(['type' => 'string', 'minimum' => 1]); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Converts value to the primitive. |
||
40 | * |
||
41 | * @param string $value |
||
42 | * @return int|float|string|bool |
||
43 | */ |
||
44 | public function convert(string $value) |
||
64 | |||
65 | } |
||
68 |