FormatsFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeFormat() 0 12 2
A make() 0 13 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\Factory;
5
6
use Innmind\Rest\Server\{
7
    Formats,
8
    Format\Format,
9
    Format\MediaType
10
};
11
use Innmind\Immutable\{
12
    Map,
13
    Set
14
};
15
16
final class FormatsFactory
17
{
18 30
    public function make(array $formats): Formats
19
    {
20 30
        $map = new Map('string', Format::class);
21
22 30
        foreach ($formats as $name => $format) {
23 30
            $map = $map->put(
24 30
                $name,
25 30
                $this->makeFormat($name, $format)
26
            );
27
        }
28
29 30
        return new Formats($map);
30
    }
31
32 30
    private function makeFormat(string $name, array $config): Format
33
    {
34 30
        $mediaTypes = new Set(MediaType::class);
35
36 30
        foreach ($config['media_types'] as $mediaType => $priority) {
37 30
            $mediaTypes = $mediaTypes->add(
38 30
                new MediaType($mediaType, $priority)
39
            );
40
        }
41
42 30
        return new Format($name, $mediaTypes, $config['priority']);
43
    }
44
}
45