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

ServerCollectionBuilder::createServerCollection()   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 ServerCollectionBuilder implements Objects\ServerCollectionFactory
10
{
11
    private $servers = [];
12
13
    public function addServers(Objects\ServerFactory ...$servers): self
14
    {
15
        foreach ($servers as $server) {
16
            $this->servers[] = $server;
17
        }
18
19
        return $this;
20
    }
21
22
    public function createServerCollection(): Objects\ServerCollection
23
    {
24
        return new Objects\ServerCollection(
25
            array_map(
26
                static function (Objects\ServerFactory $factory): Objects\Server {
27
                    return $factory->createServer();
28
                },
29
                $this->getServers()
30
            )
31
        );
32
    }
33
34
    private function getServers(): array
35
    {
36
        return $this->servers;
37
    }
38
}
39