InvalidSchemaException   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 0

Complexity

Total Complexity 7

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
dl 0
loc 109
ccs 28
cts 34
cp 0.8235
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A invalidParameterType() 0 10 1
A getKeyword() 0 4 1
A getPointer() 0 4 1
A negativeValue() 0 9 1
A emptyArray() 0 8 1
A missingProperty() 0 9 1
1
<?php
2
3
namespace League\JsonGuard\Exception;
4
5
final class InvalidSchemaException extends \RuntimeException
6
{
7
    /**
8
     * @var string
9
     */
10
    private $keyword;
11
12
    /**
13
     * @var string
14
     */
15
    private $pointer;
16
17
    /**
18
     * @param string $message
19
     * @param string $keyword
20
     * @param string $pointer
21
     */
22 86
    public function __construct($message, $keyword, $pointer)
23
    {
24 86
        parent::__construct($message);
25
26 86
        $this->keyword = $keyword;
27 86
        $this->pointer = $pointer;
28 86
    }
29
30
    /**
31
     * @param string $actualType
32
     * @param array  $allowedTypes
33
     * @param string $keyword
34
     * @param string $pointer
35
     *
36
     * @return \League\JsonGuard\Exception\InvalidSchemaException
37
     */
38 58
    public static function invalidParameterType($actualType, array $allowedTypes, $keyword, $pointer)
39
    {
40 58
        $message = sprintf(
41 58
            'Value has type "%s" but must be one of: "%s"',
42 58
            $actualType,
43 58
            implode(', ', $allowedTypes)
44 29
        );
45
46 58
        return new self($message, $keyword, $pointer);
47
    }
48
49
    /**
50
     * @param integer $value
51
     * @param string  $keyword
52
     * @param string  $pointer
53
     *
54
     * @return \League\JsonGuard\Exception\InvalidSchemaException
55
     */
56 18
    public static function negativeValue($value, $keyword, $pointer)
57
    {
58 18
        $message = sprintf(
59 18
            'Integer value "%d" must be greater than, or equal to, 0',
60 9
            $value
61 9
        );
62
63 18
        return new self($message, $keyword, $pointer);
64
    }
65
66
    /**
67
     * @param string $keyword
68
     * @param string $pointer
69
     *
70
     * @return \League\JsonGuard\Exception\InvalidSchemaException
71
     */
72 8
    public static function emptyArray($keyword, $pointer)
73
    {
74 8
        return new self(
75 8
            'Array must have at least one element',
76 8
            $keyword,
77 4
            $pointer
78 4
        );
79
    }
80
81
    /**
82
     * @param string $property
83
     * @param string $keyword
84
     * @param string $pointer
85
     *
86
     * @return \League\JsonGuard\Exception\InvalidSchemaException
87
     */
88
    public static function missingProperty($property, $keyword, $pointer)
89
    {
90
        $message = sprintf(
91
            'The schema must contain the property %s',
92
            $property
93
        );
94
95
        return new self($message, $keyword, $pointer);
96
    }
97
98
    /**
99
     * @return string
100
     */
101 8
    public function getKeyword()
102
    {
103 8
        return $this->keyword;
104
    }
105
106
    /**
107
     * @return string
108
     */
109 8
    public function getPointer()
110
    {
111 8
        return $this->pointer;
112
    }
113
}
114