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

YamlTypeDecoder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 26
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getContentType() 0 4 1
A decode() 0 8 2
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