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

JsonTypeDecoder::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
9
final class JsonTypeDecoder implements TypeDecoderInterface
10
{
11
    /**
12
     * @return string
13
     */
14 2
    public function getContentType(): string
15
    {
16 2
        return 'application/json';
17
    }
18
19
    /**
20
     * @param string $data
21
     *
22
     * @return array
23
     *
24
     * @throws DeserializerRuntimeException
25
     */
26 3
    public function decode(string $data): array
27
    {
28
        try {
29 3
            return json_decode($data, true);
30 1
        } catch (\TypeError $e) {
31 1
            throw DeserializerRuntimeException::createNotParsable($this->getContentType());
32
        }
33
    }
34
}
35