Passed
Branch release/v2.6.0 (180879)
by Anatoly
03:25 queued 36s
created

ArgumentException   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 99
ccs 27
cts 27
cp 1
rs 10
wmc 17

7 Methods

Rating   Name   Duplication   Size   Complexity  
A assertIsNotEmpty() 0 4 3
A assertIsString() 0 4 2
A assertIsInteger() 0 4 2
A assertIsArray() 0 4 2
A assertIsNotEmptyArray() 0 4 3
A assertIsNotEmptyString() 0 4 3
A assertIsSubclassOf() 0 4 2
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router\Exception;
13
14
/**
15
 * Import functions
16
 */
17
use function is_array;
18
use function is_int;
19
use function is_string;
20
use function is_subclass_of;
21
22
/**
23
 * ArgumentException
24
 *
25
 * @since 2.6.0
26
 */
27
class ArgumentException extends Exception
28
{
29
30
    /**
31
     * @param mixed $operand
32
     * @param string $message
33
     *
34
     * @return void
35
     * @throws static
36
     */
37 51
    public static function assertIsArray($operand, string $message) : void
38
    {
39 51
        if (!is_array($operand)) {
40 26
            throw new static($message);
41
        }
42 25
    }
43
44
    /**
45
     * @param mixed $operand
46
     * @param string $message
47
     *
48
     * @return void
49
     * @throws static
50
     */
51 12
    public static function assertIsInteger($operand, string $message) : void
52
    {
53 12
        if (!is_int($operand)) {
54 9
            throw new static($message);
55
        }
56 3
    }
57
58
    /**
59
     * @param mixed $operand
60
     * @param string $message
61
     *
62
     * @return void
63
     * @throws static
64
     */
65 19
    public static function assertIsString($operand, string $message) : void
66
    {
67 19
        if (!is_string($operand)) {
68 16
            throw new static($message);
69
        }
70 3
    }
71
72
    /**
73
     * @param mixed $operand
74
     * @param string $message
75
     *
76
     * @return void
77
     * @throws static
78
     */
79 101
    public static function assertIsNotEmptyArray($operand, string $message) : void
80
    {
81 101
        if ([] === $operand || !is_array($operand)) {
82 13
            throw new static($message);
83
        }
84 88
    }
85
86
    /**
87
     * @param mixed $operand
88
     * @param string $message
89
     *
90
     * @return void
91
     * @throws static
92
     */
93 173
    public static function assertIsNotEmptyString($operand, string $message) : void
94
    {
95 173
        if ('' === $operand || !is_string($operand)) {
96 73
            throw new static($message);
97
        }
98 150
    }
99
100
    /**
101
     * @param mixed $operand
102
     * @param string $className
103
     * @param string $message
104
     *
105
     * @return void
106
     * @throws static
107
     */
108 31
    public static function assertIsSubclassOf($operand, string $className, string $message) : void
109
    {
110 31
        if (!is_subclass_of($operand, $className)) {
111 25
            throw new static($message);
112
        }
113 7
    }
114
115
    /**
116
     * @param mixed $operand
117
     * @param string $message
118
     *
119
     * @return void
120
     * @throws static
121
     */
122 40
    public static function assertIsNotEmpty($operand, string $message) : void
123
    {
124 40
        if ('' === $operand || [] === $operand) {
125 4
            throw new static($message);
126
        }
127 39
    }
128
}
129