Skip to content

Commit 84ea3fa

Browse files
committed
new ArgumentException.php exception
1 parent f51b49d commit 84ea3fa

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
public static function assertIsArray($operand, string $message) : void
38+
{
39+
if (!is_array($operand)) {
40+
throw new static($message);
41+
}
42+
}
43+
44+
/**
45+
* @param mixed $operand
46+
* @param string $message
47+
*
48+
* @return void
49+
* @throws static
50+
*/
51+
public static function assertIsInteger($operand, string $message) : void
52+
{
53+
if (!is_int($operand)) {
54+
throw new static($message);
55+
}
56+
}
57+
58+
/**
59+
* @param mixed $operand
60+
* @param string $message
61+
*
62+
* @return void
63+
* @throws static
64+
*/
65+
public static function assertIsString($operand, string $message) : void
66+
{
67+
if (!is_string($operand)) {
68+
throw new static($message);
69+
}
70+
}
71+
72+
/**
73+
* @param mixed $operand
74+
* @param string $message
75+
*
76+
* @return void
77+
* @throws static
78+
*/
79+
public static function assertIsNotEmptyArray($operand, string $message) : void
80+
{
81+
if ([] === $operand || !is_array($operand)) {
82+
throw new static($message);
83+
}
84+
}
85+
86+
/**
87+
* @param mixed $operand
88+
* @param string $message
89+
*
90+
* @return void
91+
* @throws static
92+
*/
93+
public static function assertIsNotEmptyString($operand, string $message) : void
94+
{
95+
if ('' === $operand || !is_string($operand)) {
96+
throw new static($message);
97+
}
98+
}
99+
100+
/**
101+
* @param mixed $operand
102+
* @param string $className
103+
* @param string $message
104+
*
105+
* @return void
106+
* @throws static
107+
*/
108+
public static function assertIsSubclassOf($operand, string $className, string $message) : void
109+
{
110+
if (!is_subclass_of($operand, $className)) {
111+
throw new static($message);
112+
}
113+
}
114+
115+
/**
116+
* @param mixed $operand
117+
* @param string $message
118+
*
119+
* @return void
120+
* @throws static
121+
*/
122+
public static function assertIsNotEmpty($operand, string $message) : void
123+
{
124+
if ('' === $operand || [] === $operand) {
125+
throw new static($message);
126+
}
127+
}
128+
}

src/Exception/InvalidDescriptorArgumentException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
*
1717
* @since 2.6.0
1818
*/
19-
class InvalidDescriptorArgumentException extends Exception
19+
class InvalidDescriptorArgumentException extends ArgumentException
2020
{
2121
}

0 commit comments

Comments
 (0)