Completed
Push — master ( 00d376...cc54a0 )
by Veaceslav
01:15
created

ServerVariablesBuilder::setVariable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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 1
    public function addVariables(iterable $variables): self
14
    {
15 1
        foreach ($variables as $key => $variable) {
16 1
            $this->setVariable($key, $variable);
17
        }
18
19 1
        return $this;
20
    }
21
22 2
    public function createServerVariables(): Objects\ServerVariables
23
    {
24 2
        return new Objects\ServerVariables(
25 2
            array_map(
26
                static function (Objects\ServerVariableFactory $factory): Objects\ServerVariable {
27 2
                    return $factory->createServerVariable();
28 2
                },
29 2
                $this->getVariables()
30
            )
31
        );
32
    }
33
34 2
    public function setVariable(string $key, Objects\ServerVariableFactory $variable): self
35
    {
36 2
        $this->variables[$key] = $variable;
37
38 2
        return $this;
39
    }
40
41 2
    private function getVariables(): array
42
    {
43 2
        return $this->variables;
44
    }
45
}
46