Completed
Push — master ( f2d7db...e62e77 )
by Martin
01:54
created

ObjectSchema::property()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace RoundingWell\Schematic\Schema;
4
5
use RoundingWell\Schematic\Schema;
6
7
class ObjectSchema extends Schema
8
{
9
    public function phpType()
10
    {
11
        return 'object';
12
    }
13
14
    /**
15
     * @return Schema[]
16
     */
17
    public function properties()
18
    {
19
        $props = [];
20
21
        foreach ($this->schema->properties as $name => $schema) {
22
            $props[$name] = Schema::make($schema);
23
        }
24
25
        foreach ($this->schema->oneOf ?: [] as $oneOf) {
26
            foreach ($oneOf->properties as $name => $schema) {
27
                $props[$name] = Schema::make($schema);
28
            }
29
        }
30
31
        return $props;
32
    }
33
34
    /**
35
     * @return string[]
36
     */
37
    public function required()
38
    {
39
        return !is_null($this->schema->required) ? $this->schema->required : [];
40
    }
41
42
    public function isRequired($property)
43
    {
44
        return in_array($property, $this->required());
45
    }
46
}
47