DecodedValue::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 6
dl 0
loc 8
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\JsonParser\Decoders;
4
5
use Throwable;
6
7
/**
8
 * The decoded value.
9
 *
10
 */
11
final class DecodedValue
12
{
13
    /**
14
     * Retrieve a successfully decoded value
15
     *
16
     * @param mixed $value
17
     * @return self
18
     */
19 262
    public static function succeeded(mixed $value): self
20
    {
21 262
        return new self(true, $value);
22
    }
23
24
    /**
25
     * Retrieve a value failed to be decoded
26
     *
27
     * @param Throwable $e
28
     * @param string $json
29
     * @return self
30
     */
31 8
    public static function failed(Throwable $e, string $json): self
32
    {
33 8
        return new self(false, null, $e->getMessage(), $e->getCode(), $e, $json);
34
    }
35
36
    /**
37
     * Instantiate the class.
38
     *
39
     * @param mixed $value
40
     */
41 266
    private function __construct(
42
        public readonly bool $succeeded,
43
        public mixed $value = null,
44
        public readonly ?string $error = null,
45
        public readonly ?int $code = null,
46
        public readonly ?Throwable $exception = null,
47
        public readonly ?string $json = null,
48
    ) {
49 266
    }
50
}
51