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

ServerVariablesBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addVariables() 0 8 2
A createServerVariables() 0 11 1
A setVariable() 0 6 1
A getVariables() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi\Builders;
6
7
use Aweapi\Openapi\Objects;
8
9
final class ServerVariablesBuilder implements Objects\ServerVariablesFactory
10
{
11
    private $variables = [];
12
13
    public function addVariables(iterable $variables): self
14
    {
15
        foreach ($variables as $key => $variable) {
16
            $this->setVariable($key, $variable);
17
        }
18
19
        return $this;
20
    }
21
22
    public function createServerVariables(): Objects\ServerVariables
23
    {
24
        return new Objects\ServerVariables(
25
            array_map(
26
                static function (Objects\ServerVariableFactory $factory): Objects\ServerVariable {
27
                    return $factory->createServerVariable();
28
                },
29
                $this->getVariables()
30
            )
31
        );
32
    }
33
34
    public function setVariable(string $key, Objects\ServerVariableFactory $variable): self
35
    {
36
        $this->variables[$key] = $variable;
37
38
        return $this;
39
    }
40
41
    private function getVariables(): array
42
    {
43
        return $this->variables;
44
    }
45
}
46