Completed
Push — develop ( d3bb0f...88b170 )
by Baptiste
05:23
created

FormatsFactory   A

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 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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