DeserializerRuntimeException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 40
ccs 10
cts 10
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createNotParsable() 0 8 2
A createInvalidObjectType() 0 7 1
A createInvalidDataType() 0 4 1
A createNotAllowedAdditionalFields() 0 3 1
A createMissingObjectType() 0 6 1
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