Passed
Push — master ( 95e744...8d5d5e )
by Dominik
01:52
created

YamlTypeDecoder::getContentType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Decoder;
6
7
use Chubbyphp\Deserialization\DeserializerRuntimeException;
8
use Symfony\Component\Yaml\Yaml;
9
10
final class YamlTypeDecoder implements TypeDecoderInterface
11
{
12
    /**
13
     * @return string
14
     */
15 2
    public function getContentType(): string
16
    {
17 2
        return 'application/x-yaml';
18
    }
19
20
    /**
21
     * @param string $data
22
     *
23
     * @return array
24
     *
25
     * @throws DeserializerRuntimeException
26
     */
27 3
    public function decode(string $data): array
28
    {
29
        try {
30 3
            return Yaml::parse($data);
31 1
        } catch (\TypeError $e) {
32 1
            throw DeserializerRuntimeException::createNotParsable($this->getContentType());
33
        }
34
    }
35
}
36