Passed
Push — master ( f13532...bf7dba )
by Andrea Marco
02:44 queued 12s
created

JsonDecoder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\JsonParser\Decoders;
4
5
/**
6
 * The decoder using the built-in JSON decoder.
7
 *
8
 */
9
final class JsonDecoder extends AbstractDecoder
10
{
11
    /**
12
     * Instantiate the class.
13
     *
14
     * @param bool $decodesToArray
15
     * @param int<1, max> $depth
16
     */
17 3
    public function __construct(private readonly bool $decodesToArray = true, private readonly int $depth = 512)
18
    {
19 3
    }
20
21
    /**
22
     * Retrieve the decoded value of the given JSON
23
     *
24
     * @param string $json
25
     * @return mixed
26
     * @throws \Throwable
27
     */
28 3
    protected function decodeJson(string $json): mixed
29
    {
30 3
        return json_decode($json, $this->decodesToArray, $this->depth, JSON_THROW_ON_ERROR);
31
    }
32
}
33