FormatRetriever   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getContentType() 0 7 2
A getFormat() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Apie\CorePlugin\Encodings;
4
5
use Apie\Core\Interfaces\FormatRetrieverInterface;
6
7
/**
8
 * Converts between the format string used for the symfony serializer and the request/response header to indicate
9
 * the mime type.
10
 */
11
class FormatRetriever implements FormatRetrieverInterface
12
{
13
    private $mapping;
14
15
    public function __construct(array $mapping = [])
16
    {
17
        $this->mapping = $mapping;
18
    }
19
    /**
20
     * @param string $contentType
21
     * @return string|null
22
     */
23
    public function getFormat(string $contentType): ?string
24
    {
25
        return $this->mapping[$contentType] ?? null;
26
    }
27
28
    public function getContentType(string $format): ?string
29
    {
30
        $res = array_search($format, $this->mapping);
31
        if ($res === false) {
32
            return null;
33
        }
34
        return $res;
35
    }
36
}
37