|
2 | 2 |
|
3 | 3 | namespace MongoDB\Codec; |
4 | 4 |
|
| 5 | +use MongoDB\Exception\InvalidArgumentException; |
| 6 | + |
5 | 7 | /** |
6 | 8 | * @internal |
7 | 9 | * @psalm-template BSONType |
|
10 | 12 | interface Decoder |
11 | 13 | { |
12 | 14 | /** |
| 15 | + * Checks if the decoder supports a given value. |
| 16 | + * |
13 | 17 | * @param mixed $value |
14 | 18 | * @psalm-assert-if-true BSONType $value |
15 | 19 | */ |
16 | 20 | public function canDecode($value): bool; |
17 | 21 |
|
18 | 22 | /** |
| 23 | + * Decodes a given value. If the decoder does not support the value, it |
| 24 | + * should throw an exception. |
| 25 | + * |
19 | 26 | * @param mixed $value |
20 | 27 | * @psalm-param BSONType $value |
21 | 28 | * @return mixed |
22 | 29 | * @psalm-return NativeType |
| 30 | + * @throws InvalidArgumentException if the decoder does not support the value |
23 | 31 | */ |
24 | 32 | public function decode($value); |
25 | 33 |
|
26 | 34 | /** |
| 35 | + * Decodes a given value if supported, otherwise returns the value as-is. |
| 36 | + * |
| 37 | + * The DecodeIfSupported trait provides a default implementation of this |
| 38 | + * method. |
| 39 | + * |
27 | 40 | * @param mixed $value |
28 | 41 | * @psalm-param mixed $value |
29 | 42 | * @return mixed |
|
0 commit comments