Skip to content

Commit 34f93eb

Browse files
committed
Remove explicit values in runtime exceptions
1 parent fa81b26 commit 34f93eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+119
-210
lines changed

example/03.types/03.custom-type-template-arguments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function cast(mixed $value, Context $context): mixed
6363
return $this->type->cast($value, $context);
6464
}
6565

66-
throw InvalidValueException::createFromContext($value, $context);
66+
throw InvalidValueException::createFromContext($context);
6767
}
6868
}
6969

src/Exception/Runtime/ClassException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @template-extends ValueOfTypeException<class-string<TObject>>
1313
*/
1414
abstract class ClassException extends ValueOfTypeException implements
15-
FinalExceptionInterface
15+
NotInterceptableExceptionInterface
1616
{
1717
/**
1818
* @param class-string<TObject> $class unlike {@see ValueException::$value},

src/Exception/Runtime/InvalidIterableKeyException.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,19 @@ public static function createFromPath(
4242
}
4343

4444
/**
45-
* @template TArgValue of iterable
46-
*
47-
* @param int<0, max> $index
48-
* @param TArgValue $value
49-
*
50-
* @return self<TArgValue>
45+
* @return self<iterable<array-key, mixed>>
5146
*/
5247
public static function createFromContext(
5348
int $index,
5449
mixed $key,
55-
iterable $value,
5650
Context $context,
5751
?\Throwable $previous = null,
5852
): self {
53+
/** @var self<iterable<array-key, mixed>> */
5954
return self::createFromPath(
6055
index: $index,
6156
key: $key,
62-
value: $value,
57+
value: $context->value,
6358
path: $context->getPath(),
6459
previous: $previous,
6560
);

src/Exception/Runtime/InvalidIterableValueException.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,21 @@ public static function createFromPath(
5050
}
5151

5252
/**
53-
* @template TArgValue of iterable
54-
*
55-
* @param int<0, max> $index
56-
* @param TArgValue $value
57-
*
58-
* @return self<TArgValue>
53+
* @return self<iterable<array-key, mixed>>
5954
*/
6055
public static function createFromContext(
6156
mixed $element,
6257
int $index,
6358
mixed $key,
64-
mixed $value,
6559
Context $context,
6660
?\Throwable $previous = null,
6761
): self {
62+
/** @var self<iterable<array-key, mixed>> */
6863
return self::createFromPath(
6964
element: $element,
7065
index: $index,
7166
key: $key,
72-
value: $value,
67+
value: $context->value,
7368
path: $context->getPath(),
7469
previous: $previous,
7570
);

src/Exception/Runtime/InvalidObjectValueException.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,21 @@ public static function createFromPath(
4545
}
4646

4747
/**
48-
* @template TArgValue of array|object
49-
*
50-
* @param non-empty-string $field
51-
* @param TArgValue $value
52-
*
53-
* @return self<TArgValue>
48+
* @return self<array<array-key, mixed>|object>
5449
*/
5550
public static function createFromContext(
5651
mixed $element,
5752
string $field,
5853
?TypeStatement $expected,
59-
array|object $value,
6054
Context $context,
6155
?\Throwable $previous = null,
6256
): self {
57+
/** @var self<array<array-key, mixed>|object> */
6358
return self::createFromPath(
6459
element: $element,
6560
field: $field,
6661
expected: $expected,
67-
value: $value,
62+
value: $context->value,
6863
path: $context->getPath(),
6964
previous: $previous,
7065
);

src/Exception/Runtime/InvalidValueException.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,14 @@ public static function createFromPath(
3737
}
3838

3939
/**
40-
* @template TArgValue of mixed
41-
*
42-
* @param TArgValue $value
43-
*
44-
* @return self<TArgValue>
40+
* @return self<mixed>
4541
*/
4642
public static function createFromContext(
47-
mixed $value,
4843
Context $context,
4944
?\Throwable $previous = null,
5045
): self {
5146
return self::createFromPath(
52-
value: $value,
47+
value: $context->value,
5348
path: $context->getPath(),
5449
previous: $previous,
5550
);

src/Exception/Runtime/InvalidValueOfTypeException.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @template-extends ValueOfTypeException<TValue>
1414
*/
1515
class InvalidValueOfTypeException extends ValueOfTypeException implements
16-
FinalExceptionInterface
16+
NotInterceptableExceptionInterface
1717
{
1818
/**
1919
* @template TArgValue of mixed
@@ -41,21 +41,16 @@ public static function createFromPath(
4141
}
4242

4343
/**
44-
* @template TArgValue of mixed
45-
*
46-
* @param TArgValue $value
47-
*
48-
* @return self<TArgValue>
44+
* @return self<mixed>
4945
*/
5046
public static function createFromContext(
5147
TypeStatement $expected,
52-
mixed $value,
5348
Context $context,
5449
?\Throwable $previous = null,
5550
): self {
5651
return self::createFromPath(
5752
expected: $expected,
58-
value: $value,
53+
value: $context->value,
5954
path: $context->getPath(),
6055
previous: $previous,
6156
);

src/Exception/Runtime/IterableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @template-extends ValueException<TValue>
1212
*/
1313
abstract class IterableException extends ValueException implements
14-
FinalExceptionInterface
14+
NotInterceptableExceptionInterface
1515
{
1616
/**
1717
* @param TValue $value unlike {@see ValueException::$value}, this exception

src/Exception/Runtime/MissingRequiredObjectFieldException.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,19 @@ public static function createFromPath(
4343
}
4444

4545
/**
46-
* @template TArgValue of array|object
47-
*
48-
* @param non-empty-string $field
49-
* @param TArgValue $value
50-
*
51-
* @return self<TArgValue>
46+
* @return self<array<array-key, mixed>|object>
5247
*/
5348
public static function createFromContext(
5449
string $field,
5550
?TypeStatement $expected,
56-
array|object $value,
5751
Context $context,
5852
?\Throwable $previous = null,
5953
): self {
54+
/** @var self<array<array-key, mixed>|object> */
6055
return self::createFromPath(
6156
field: $field,
6257
expected: $expected,
63-
value: $value,
58+
value: $context->value,
6459
path: $context->getPath(),
6560
previous: $previous,
6661
);

src/Exception/Runtime/FinalExceptionInterface.php renamed to src/Exception/Runtime/NotInterceptableExceptionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
* }
3434
* ```
3535
*/
36-
interface FinalExceptionInterface extends MapperExceptionInterface {}
36+
interface NotInterceptableExceptionInterface extends MapperExceptionInterface {}

0 commit comments

Comments
 (0)