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

JsonDecoderType::getContentType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Decoder;
6
7
final class JsonDecoderType implements DecoderTypeInterface
8
{
9
    /**
10
     * @var int
11
     */
12
    private $level;
13
14
    /**
15
     * @var int
16
     */
17
    private $options;
18
19
    /**
20
     * JsonTransformer constructor.
21
     *
22
     * @param int $options
23
     * @param int $level
24
     */
25
    public function __construct(int $level = 512, int $options = 0)
26
    {
27
        $this->options = $options;
28
        $this->level = $level;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getContentType(): string
35
    {
36
        return 'application/json';
37
    }
38
39
    /**
40
     * @param string $data
41
     *
42
     * @return array
43
     *
44
     * @throws DecoderException
45
     */
46
    public function decode(string $data): array
47
    {
48
        try {
49
            return json_decode($data, true, $this->level, $this->options);
50
        } 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...
51
            throw DecoderException::createNotParsable($this->getContentType());
52
        }
53
    }
54
}
55