Completed
Push — master ( e98ae3...0e888f )
by Matt
02:50
created

InvalidSchemaException::emptyArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace League\JsonGuard\Exceptions;
4
5
class InvalidSchemaException extends \RuntimeException
6
{
7
    /**
8
     * @var string
9
     */
10
    private $keyword;
11
12
    /**
13
     * @var string|null
14
     */
15
    private $pointer;
16
17
    /**
18
     * @param string      $message
19
     * @param string      $keyword
20
     * @param string|null $pointer
21
     */
22 78
    public function __construct($message, $keyword, $pointer)
23
    {
24 78
        parent::__construct($message);
25
26 78
        $this->keyword = $keyword;
27 78
        $this->pointer = $pointer;
28 78
    }
29
30
    /**
31
     * @param string      $actualType
32
     * @param array       $allowedTypes
33
     * @param string      $keyword
34
     * @param string|null $pointer
35
     *
36
     * @return \League\JsonGuard\Exceptions\InvalidSchemaException
37
     */
38 56
    public static function invalidParameterType($actualType, array $allowedTypes, $keyword, $pointer)
39
    {
40 56
        $message = sprintf(
41 56
            'Value has type "%s" but must be one of: "%s"',
42 56
            $actualType,
43 56
            implode(', ', $allowedTypes)
44 56
        );
45
46 56
        return new self($message, $keyword, $pointer);
47
    }
48
49
    /**
50
     * @param integer     $value
51
     * @param string      $keyword
52
     * @param string|null $pointer
53
     *
54
     * @return \League\JsonGuard\Exceptions\InvalidSchemaException
55
     */
56 16
    public static function negativeValue($value, $keyword, $pointer)
57
    {
58 16
        $message = sprintf(
59 16
            'Integer value "%d" must be greater than, or equal to, 0',
60
            $value
61 16
        );
62
63 16
        return new self($message, $keyword, $pointer);
64
    }
65
66
    /**
67
     * @param string      $keyword
68
     * @param string|null $pointer
69
     *
70
     * @return \League\JsonGuard\Exceptions\InvalidSchemaException
71
     */
72 6
    public static function emptyArray($keyword, $pointer)
73
    {
74 6
        return new self(
75 6
            'Array must have at least one element',
76 6
            $keyword,
77
            $pointer
78 6
        );
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getKeyword()
85
    {
86
        return $this->keyword;
87
    }
88
89
    /**
90
     * @return string|null
91
     */
92
    public function getPointer()
93
    {
94
        return $this->pointer;
95
    }
96
}
97