1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Chubbyphp\Deserialization; |
6
|
|
|
|
7
|
|
|
final class DeserializerRuntimeException extends \RuntimeException |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @param string $path |
11
|
|
|
* @param string $givenType |
12
|
|
|
* @param string $wishedType |
13
|
|
|
* |
14
|
|
|
* @return self |
15
|
|
|
*/ |
16
|
1 |
|
public static function createInvalidDataType(string $path, string $givenType, string $wishedType): self |
17
|
|
|
{ |
18
|
1 |
|
return new self( |
19
|
1 |
|
sprintf('There is an invalid data type "%s", needed "%s" at path: "%s"', $givenType, $wishedType, $path) |
20
|
|
|
); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param string $path |
25
|
|
|
* @param string $givenType |
26
|
|
|
* @param array $allowedTypes |
27
|
|
|
* |
28
|
|
|
* @return self |
29
|
|
|
*/ |
30
|
1 |
|
public static function createInvalidObjectType(string $path, string $givenType, array $allowedTypes): self |
31
|
|
|
{ |
32
|
1 |
|
return new self( |
33
|
1 |
|
sprintf( |
34
|
1 |
|
'There is an invalid object type "%s", allowed types are "%s" at path: "%s"', |
35
|
1 |
|
$givenType, |
36
|
1 |
|
implode('", "', $allowedTypes), |
37
|
1 |
|
$path |
38
|
|
|
) |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $path |
44
|
|
|
* @param array $allowedTypes |
45
|
|
|
* |
46
|
|
|
* @return self |
47
|
|
|
*/ |
48
|
1 |
|
public static function createMissingObjectType(string $path, array $allowedTypes): self |
49
|
|
|
{ |
50
|
1 |
|
return new self( |
51
|
1 |
|
sprintf( |
52
|
1 |
|
'Missing object type, allowed types are "%s" at path: "%s"', |
53
|
1 |
|
implode('", "', $allowedTypes), |
54
|
1 |
|
$path |
55
|
|
|
) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $contentType |
61
|
|
|
* |
62
|
|
|
* @return self |
63
|
|
|
*/ |
64
|
1 |
|
public static function createNotParsable(string $contentType): self |
65
|
|
|
{ |
66
|
1 |
|
return new self(sprintf('Data is not parsable with content-type: "%s"', $contentType)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param array $paths |
71
|
|
|
* |
72
|
|
|
* @return self |
73
|
|
|
*/ |
74
|
1 |
|
public static function createNotAllowedAddtionalFields(array $paths): self |
75
|
|
|
{ |
76
|
1 |
|
return new self(sprintf('There are additional field(s) at paths: "%s"', implode('", "', $paths))); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|