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

ExamplesBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addExamples() 0 8 2
A createExamples() 0 11 1
A setExample() 0 6 1
A getExamples() 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 ExamplesBuilder implements Objects\ExamplesFactory
10
{
11
    private $examples = [];
12
13 2
    public function addExamples(iterable $variables): self
14
    {
15 2
        foreach ($variables as $key => $variable) {
16 2
            $this->setExample($key, $variable);
17
        }
18
19 2
        return $this;
20
    }
21
22 5
    public function createExamples(): Objects\Examples
23
    {
24 5
        return new Objects\Examples(
25 5
            array_map(
26
                static function (Objects\ExampleAggregateFactory $factory): Objects\ExampleAggregate {
27 5
                    return $factory->createExampleAggregate();
28 5
                },
29 5
                $this->getExamples()
30
            )
31
        );
32
    }
33
34 5
    public function setExample(string $name, Objects\ExampleAggregateFactory $example): self
35
    {
36 5
        $this->examples[$name] = $example;
37
38 5
        return $this;
39
    }
40
41 5
    private function getExamples(): array
42
    {
43 5
        return $this->examples;
44
    }
45
}
46