Completed
Pull Request — master (#6)
by Veaceslav
02:38 queued 01:30
created

MediaTypesBuilder::addMediaTypes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi\Builders;
6
7
use Aweapi\Openapi\Objects;
8
9
final class MediaTypesBuilder implements Objects\MediaTypesFactory
10
{
11
    private $mediaTypes = [];
12
13 1
    public function addMediaTypes(iterable $mediaTypes): self
14
    {
15 1
        foreach ($mediaTypes as $key => $mediaType) {
16 1
            $this->setMediaType($key, $mediaType);
17
        }
18
19 1
        return $this;
20
    }
21
22 6
    public function createMediaTypes(): Objects\MediaTypes
23
    {
24 6
        return new Objects\MediaTypes(
25 6
            array_map(
26
                static function (Objects\MediaTypeFactory $factory): Objects\MediaType {
27 2
                    return $factory->createMediaType();
28 6
                },
29 6
                $this->getMediaTypes()
30
            )
31
        );
32
    }
33
34 2
    public function setMediaType(string $key, Objects\MediaTypeFactory $mediaType): self
35
    {
36 2
        $this->mediaTypes[$key] = $mediaType;
37
38 2
        return $this;
39
    }
40
41 6
    private function getMediaTypes(): array
42
    {
43 6
        return $this->mediaTypes;
44
    }
45
}
46