InputStringIsInvalid::detected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Json;
5
6
use InvalidArgumentException as InvalidArgument;
7
8
/**
9
 * Exception to notify that the input data cannot be decoded from json format.
10
 *
11
 * @author Stratadox
12
 */
13
final class InputStringIsInvalid extends InvalidArgument implements InvalidJson
14
{
15
    /**
16
     * Produces an `Invalid Json` type exception, to throw when decoding the
17
     * input caused an error.
18
     *
19
     * @param string $error       The error message that was detected.
20
     * @param string $invalidJson The (invalid) json input that was provided.
21
     * @return InvalidJson        The Json context-specific exception to throw.
22
     */
23
    public static function detected(
24
        string $error,
25
        string $invalidJson
26
    ): InvalidJson {
27
        return new self(sprintf(
28
            'Decoding the input `%s` caused an error: %s.',
29
            $invalidJson,
30
            $error
31
        ));
32
    }
33
}
34