Completed
Pull Request — master (#108)
by Matt
01:55
created

InvalidSchemaException   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 109
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 negativeValue() 0 9 1
A emptyArray() 0 8 1
A missingProperty() 0 9 1
A getKeyword() 0 4 1
A getPointer() 0 4 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
    public function __construct($message, $keyword, $pointer)
23
    {
24
        parent::__construct($message);
25
26
        $this->keyword = $keyword;
27
        $this->pointer = $pointer;
28
    }
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
    public static function invalidParameterType($actualType, array $allowedTypes, $keyword, $pointer)
39
    {
40
        $message = sprintf(
41
            'Value has type "%s" but must be one of: "%s"',
42
            $actualType,
43
            implode(', ', $allowedTypes)
44
        );
45
46
        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
    public static function negativeValue($value, $keyword, $pointer)
57
    {
58
        $message = sprintf(
59
            'Integer value "%d" must be greater than, or equal to, 0',
60
            $value
61
        );
62
63
        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
    public static function emptyArray($keyword, $pointer)
73
    {
74
        return new self(
75
            'Array must have at least one element',
76
            $keyword,
77
            $pointer
78
        );
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
    public function getKeyword()
102
    {
103
        return $this->keyword;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getPointer()
110
    {
111
        return $this->pointer;
112
    }
113
}
114