Passed
Push — master ( 64cabf...0d88ff )
by Dominik
02:04
created

createInvalidDataType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
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