createNotAllowedAdditionalFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization;
6
7
final class DeserializerRuntimeException extends \RuntimeException
8
{
9
    public static function createInvalidDataType(string $path, string $givenType, string $wishedType): self
10
    {
11
        return new self(
12
            sprintf('There is an invalid data type "%s", needed "%s" at path: "%s"', $givenType, $wishedType, $path)
13
        );
14
    }
15
16 1
    public static function createNotParsable(string $contentType, string $error = null): self
17
    {
18 1
        $message = sprintf('Data is not parsable with content-type: "%s"', $contentType);
19 1
        if (null !== $error) {
20
            $message .= sprintf(', error: "%s"', $error);
21
        }
22
23
        return new self($message);
24
    }
25
26
    public static function createNotAllowedAdditionalFields(array $paths): self
27
    {
28
        return new self(sprintf('There are additional field(s) at paths: "%s"', implode('", "', $paths)));
29 2
    }
30
31 2
    public static function createMissingObjectType(string $path, array $supportedTypes): self
32 2
    {
33 1
        return new self(sprintf(
34
            'Missing object type, supported are "%s" at path: "%s"',
35
            implode('", "', $supportedTypes),
36 2
            $path
37
        ));
38
    }
39
40
    public static function createInvalidObjectType(string $path, string $type, array $supportedTypes): self
41
    {
42
        return new self(sprintf(
43
            'Unsupported object type "%s", supported are "%s" at path: "%s"',
44 1
            $type,
45
            implode('", "', $supportedTypes),
46 1
            $path
47
        ));
48
    }
49
}
50