FormatRetriever::getFormat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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