InputStringIsInvalid   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 5
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A detected() 0 8 1
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