Completed
Push — master ( eb47af...bb59c7 )
by Woody
01:18
created

ObjectSchema::properties()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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