Test Setup Failed
Push — main ( e03535...dde247 )
by Pieter
03:39
created

SchemaTypes   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 48
c 2
b 1
f 1
dl 0
loc 73
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getConflictedFields() 0 50 6
A getRequiredFields() 0 3 1
1
<?php
2
3
4
namespace Apie\OpenapiSchema\ValueObjects;
5
6
use Apie\ValueObjects\StringEnumTrait;
7
use Apie\ValueObjects\ValueObjectInterface;
8
9
/**
10
 * Enum for all allowed types in a schema.
11
 */
12
class SchemaTypes implements ValueObjectInterface
13
{
14
    use StringEnumTrait;
15
16
    const ARRAY = 'array';
17
18
    const INTEGER = 'integer';
19
20
    const FLOAT = 'float';
21
22
    const STRING = 'string';
23
24
    const OBJECT = 'object';
25
26
    const BOOLEAN = 'boolean';
27
28
    const NUMBER = 'number';
29
30
    public function getRequiredFields()
31
    {
32
        return [];
33
    }
34
35
    public function getConflictedFields()
36
    {
37
        $conflictedFields = [];
38
        if ($this->value !== self::OBJECT) {
39
            array_push(
40
                $conflictedFields,
41
                'properties',
42
                'additionalProperties',
43
                'required',
44
                'minProperties',
45
                'maxProperties'
46
            );
47
        }
48
        if ($this->value !== self::STRING) {
49
            array_push(
50
                $conflictedFields,
51
                'minLength',
52
                'maxLength',
53
                'pattern',
54
                'minProperties',
55
                'maxProperties'
56
            );
57
        }
58
        if ($this->value !== self::ARRAY) {
59
            array_push(
60
                $conflictedFields,
61
                'items',
62
                'minItems',
63
                'maxItems',
64
                'uniqueItems'
65
            );
66
        }
67
        if (!in_array($this->value, [self::NUMBER, self::INTEGER])) {
68
            array_push(
69
                $conflictedFields,
70
                'multipleOf',
71
                'minimum',
72
                'exclusiveMinimum',
73
                'maximum',
74
                'exclusiveMaximum'
75
            );
76
        }
77
        if (!in_array($this->value, [self::NUMBER, self::INTEGER, self::STRING])) {
78
            array_push(
79
                $conflictedFields,
80
                'format',
81
                'enum'
82
            );
83
        }
84
        return $conflictedFields;
85
    }
86
}
87