Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 131a3e5

Browse files
committed
chore: refactored UnexpectedTypeException messages
1 parent f48b9eb commit 131a3e5

File tree

16 files changed

+18
-20
lines changed

16 files changed

+18
-20
lines changed

src/Exception/UnexpectedTypeException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
class UnexpectedTypeException extends UnexpectedValueException
66
{
7-
public function __construct(string $expected, string $given)
7+
public function __construct(mixed $value, string $expectedType)
88
{
9-
$message = \sprintf('Expected value of type "%s", "%s" given.', $expected, $given);
9+
$message = \sprintf('Expected value of type "%s", "%s" given.', $expectedType, \get_debug_type($value));
1010

1111
parent::__construct($message);
1212
}

src/Rule/Choice.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
public function assert(mixed $value, ?string $name = null): void
3434
{
3535
if ($this->multiple && !\is_array($value)) {
36-
throw new UnexpectedTypeException('array', get_debug_type($value));
36+
throw new UnexpectedTypeException($value, 'array');
3737
}
3838

3939
if (
@@ -42,9 +42,7 @@ public function assert(mixed $value, ?string $name = null): void
4242
&& $this->max !== null
4343
&& $this->min > $this->max
4444
) {
45-
throw new UnexpectedValueException(
46-
'Maximum value must be greater than or equal to minimum value.'
47-
);
45+
throw new UnexpectedValueException('Maximum value must be greater than or equal to minimum value.');
4846
}
4947

5048
if ($this->multiple) {

src/Rule/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function assert(mixed $value, ?string $name = null): void
4141
}
4242

4343
if (!\is_iterable($value)) {
44-
throw new UnexpectedTypeException('array|\Traversable', get_debug_type($value));
44+
throw new UnexpectedTypeException($value, 'array|\Traversable');
4545
}
4646

4747
foreach ($this->fields as $field => $validator) {

src/Rule/Count.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function assert(mixed $value, ?string $name = null): void
4141
}
4242

4343
if (!\is_countable($value)) {
44-
throw new UnexpectedTypeException('array|\Countable', get_debug_type($value));
44+
throw new UnexpectedTypeException($value, 'array|\Countable');
4545
}
4646

4747
$numElements = \count($value);

src/Rule/Country.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function assert(mixed $value, ?string $name = null): void
3434
}
3535

3636
if (!\is_string($value)) {
37-
throw new UnexpectedTypeException('string', get_debug_type($value));
37+
throw new UnexpectedTypeException($value, 'string');
3838
}
3939

4040
// keep original value for parameters

src/Rule/CssColor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function assert(mixed $value, ?string $name = null): void
9090
}
9191

9292
if (!\is_string($value)) {
93-
throw new UnexpectedTypeException('string', get_debug_type($value));
93+
throw new UnexpectedTypeException($value, 'string');
9494
}
9595

9696
foreach ($this->formats as $format) {

src/Rule/DateTime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
public function assert(mixed $value, ?string $name = null): void
2121
{
2222
if (!\is_scalar($value) && !$value instanceof \Stringable) {
23-
throw new UnexpectedTypeException('string|\Stringable', get_debug_type($value));
23+
throw new UnexpectedTypeException($value, 'string|\Stringable');
2424
}
2525

2626
$value = (string) $value;

src/Rule/EachKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
public function assert(mixed $value, ?string $name = null): void
2323
{
2424
if (!\is_iterable($value)) {
25-
throw new UnexpectedTypeException('array|\Traversable', get_debug_type($value));
25+
throw new UnexpectedTypeException($value, 'array|\Traversable');
2626
}
2727

2828
foreach ($value as $key => $element) {

src/Rule/EachValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
public function assert(mixed $value, ?string $name = null): void
2323
{
2424
if (!\is_iterable($value)) {
25-
throw new UnexpectedTypeException('array|\Traversable', get_debug_type($value));
25+
throw new UnexpectedTypeException($value, 'array|\Traversable');
2626
}
2727

2828
foreach ($value as $key => $element) {

src/Rule/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function assert(mixed $value, ?string $name = null): void
4646
}
4747

4848
if (!\is_string($value)) {
49-
throw new UnexpectedTypeException('string', get_debug_type($value));
49+
throw new UnexpectedTypeException($value, 'string');
5050
}
5151

5252
if ($this->normalizer !== null) {

0 commit comments

Comments
 (0)