Test Setup Failed
Push — master ( b50703...9d91c5 )
by Dominik
06:16
created

YamlDecoderType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
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 Symfony\Component\Yaml\Yaml;
8
9
final class YamlDecoderType implements DecoderTypeInterface
10
{
11
    /**
12
     * @var int
13
     */
14
    private $flags;
15
16
    /**
17
     * @param int $flags
18
     */
19
    public function __construct(int $flags = 0)
20
    {
21
        $this->flags = $flags;
22
    }
23
24
    /**
25
     * @return string
26
     */
27
    public function getContentType(): string
28
    {
29
        return 'application/x-yaml';
30
    }
31
32
    /**
33
     * @param string $data
34
     *
35
     * @return array
36
     *
37
     * @throws DecoderException
38
     */
39
    public function decode(string $data): array
40
    {
41
        try {
42
            return Yaml::parse($data, $this->flags);
43
        } catch (\TypeError $e) {
0 ignored issues
show
Bug introduced by
The class TypeError does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
44
            throw DecoderException::createNotParsable($this->getContentType());
45
        }
46
    }
47
}
48