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

JsonTransformationFailure   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 26
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

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