Completed
Push — master ( bb59c7...b639e0 )
by Woody
01:20
created

ObjectSchema::property()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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