Completed
Pull Request — master (#6)
by Veaceslav
11:19
created

SchemasBuilder::createSchemas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi\Builders;
6
7
use Aweapi\Openapi\Objects;
8
9
final class SchemasBuilder implements Objects\SchemasFactory
10
{
11
    private $schemas = [];
12
13
    public function addSchemas(iterable $schemas): self
14
    {
15
        foreach ($schemas as $key => $schema) {
16
            $this->setSchema($key, $schema);
17
        }
18
19
        return $this;
20
    }
21
22
    public function createSchemas(): Objects\Schemas
23
    {
24
        return new Objects\Schemas(
25
            array_map(
26
                static function (Objects\SchemaFactory $factory): Objects\Schema {
27
                    return $factory->createSchema();
28
                },
29
                $this->getSchemas()
30
            )
31
        );
32
    }
33
34
    public function setSchema(string $key, Objects\SchemaFactory $schema): self
35
    {
36
        $this->schemas[$key] = $schema;
37
38
        return $this;
39
    }
40
41
    private function getSchemas(): array
42
    {
43
        return $this->schemas;
44
    }
45
}
46