Skip to content

Commit 8f13c74

Browse files
committed
storing an invalid value in the exception context
1 parent 1808796 commit 8f13c74

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/Exception/ArgumentException.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class ArgumentException extends Exception
3737
public static function assertIsArray($operand, string $message) : void
3838
{
3939
if (!is_array($operand)) {
40-
throw new static($message);
40+
throw new static($message, [
41+
'invalidValue' => $operand,
42+
]);
4143
}
4244
}
4345

@@ -51,7 +53,9 @@ public static function assertIsArray($operand, string $message) : void
5153
public static function assertIsInteger($operand, string $message) : void
5254
{
5355
if (!is_int($operand)) {
54-
throw new static($message);
56+
throw new static($message, [
57+
'invalidValue' => $operand,
58+
]);
5559
}
5660
}
5761

@@ -65,7 +69,9 @@ public static function assertIsInteger($operand, string $message) : void
6569
public static function assertIsString($operand, string $message) : void
6670
{
6771
if (!is_string($operand)) {
68-
throw new static($message);
72+
throw new static($message, [
73+
'invalidValue' => $operand,
74+
]);
6975
}
7076
}
7177

@@ -79,7 +85,9 @@ public static function assertIsString($operand, string $message) : void
7985
public static function assertIsNotEmptyArray($operand, string $message) : void
8086
{
8187
if ([] === $operand || !is_array($operand)) {
82-
throw new static($message);
88+
throw new static($message, [
89+
'invalidValue' => $operand,
90+
]);
8391
}
8492
}
8593

@@ -93,7 +101,9 @@ public static function assertIsNotEmptyArray($operand, string $message) : void
93101
public static function assertIsNotEmptyString($operand, string $message) : void
94102
{
95103
if ('' === $operand || !is_string($operand)) {
96-
throw new static($message);
104+
throw new static($message, [
105+
'invalidValue' => $operand,
106+
]);
97107
}
98108
}
99109

@@ -108,7 +118,9 @@ public static function assertIsNotEmptyString($operand, string $message) : void
108118
public static function assertIsSubclassOf($operand, string $className, string $message) : void
109119
{
110120
if (!is_subclass_of($operand, $className)) {
111-
throw new static($message);
121+
throw new static($message, [
122+
'invalidValue' => $operand,
123+
]);
112124
}
113125
}
114126

@@ -122,7 +134,9 @@ public static function assertIsSubclassOf($operand, string $className, string $m
122134
public static function assertIsNotEmpty($operand, string $message) : void
123135
{
124136
if ('' === $operand || [] === $operand) {
125-
throw new static($message);
137+
throw new static($message, [
138+
'invalidValue' => $operand,
139+
]);
126140
}
127141
}
128142
}

0 commit comments

Comments
 (0)