DecodedValue   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 38
ccs 5
cts 5
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A succeeded() 0 3 1
A failed() 0 3 1
A __construct() 0 8 1
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