Passed
Push — master ( d4b74b...f37c5f )
by Jesse
01:55
created

JsonTransformationFailure::detected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Hydration\Mapping\Transform;
4
5
use RuntimeException;
6
use Stratadox\HydrationMapping\MappingFailure;
7
use function gettype;
8
use function sprintf;
9
10
final class JsonTransformationFailure extends RuntimeException implements MappingFailure
11
{
12
    public static function detected(
13
        string $error,
14
        string $key,
15
        string $name
16
    ): MappingFailure {
17
        return new self(sprintf(
18
            'Error in transforming the json from key `%s` for in the property `%s`: %s',
19
            $key,
20
            $name,
21
            $error
22
        ));
23
    }
24
25
    public static function cannotBeScalar(
26
        $value,
27
        string $key,
28
        string $name
29
    ): self {
30
        return new self(sprintf(
31
            'Unexpected %s while transforming the json from key `%s` for in ' .
32
            'the property `%s`: expecting an array',
33
            gettype($value),
34
            $key,
35
            $name
36
        ));
37
    }
38
}
39