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

ObjectSchema   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A phpType() 0 4 1
A property() 0 4 1
A properties() 0 10 2
A required() 0 4 2
A isRequired() 0 4 1
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