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

JsonTypeDecoder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
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
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