AbstractDecoder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 26
ccs 5
cts 5
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A decode() 0 9 2
1
<?php
2
3
namespace Cerbero\JsonParser\Decoders;
4
5
use Throwable;
6
7
/**
8
 * The abstract implementation of a JSON decoder.
9
 *
10
 */
11
abstract class AbstractDecoder implements Decoder
12
{
13
    /**
14
     * Retrieve the decoded value of the given JSON
15
     *
16
     * @param string $json
17
     * @return mixed
18
     * @throws Throwable
19
     */
20
    abstract protected function decodeJson(string $json): mixed;
21
22
    /**
23
     * Decode the given JSON.
24
     *
25
     * @param string $json
26
     * @return DecodedValue
27
     */
28 266
    public function decode(string $json): DecodedValue
29
    {
30
        try {
31 266
            $value = $this->decodeJson($json);
32 8
        } catch (Throwable $e) {
33 8
            return DecodedValue::failed($e, $json);
34
        }
35
36 262
        return DecodedValue::succeeded($value);
37
    }
38
}
39