JsonTransformationFailure::detected()   A
last analyzed

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 sprintf;
8
9
final class JsonTransformationFailure extends RuntimeException implements MappingFailure
10
{
11
    public static function detected(
12
        string $error,
13
        string $key,
14
        string $name
15
    ): MappingFailure {
16
        return new self(sprintf(
17
            'Error in transforming the json from key `%s` for in the property `%s`: %s',
18
            $key,
19
            $name,
20
            $error
21
        ));
22
    }
23
24
    public static function cannotBeScalar(
25
        string $type,
26
        string $key,
27
        string $name
28
    ): self {
29
        return new self(sprintf(
30
            'Unexpected %s while transforming the json from key `%s` for in ' .
31
            'the property `%s`: expecting an array',
32
            $type,
33
            $key,
34
            $name
35
        ));
36
    }
37
}
38