YamlTypeDecoder::getContentType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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