Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| RefusesJson | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| jsonSerialize | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celema\Boiler\Proxy; |
| 6 | |
| 7 | use Celema\Boiler\Exception\RuntimeException; |
| 8 | use Override; |
| 9 | |
| 10 | /** |
| 11 | * Fails `json_encode()` for a proxy. Without it, a proxy is encoded as `{}`: |
| 12 | * the encoder sees an object without public properties instead of the |
| 13 | * wrapped value. |
| 14 | * |
| 15 | * Requires the using class to implement `JsonSerializable`. |
| 16 | * |
| 17 | * @internal |
| 18 | */ |
| 19 | trait RefusesJson |
| 20 | { |
| 21 | #[Override] |
| 22 | public function jsonSerialize(): never |
| 23 | { |
| 24 | throw new RuntimeException( |
| 25 | 'A wrapped value cannot be encoded as JSON; encode the original: json_encode(u($value))', |
| 26 | ); |
| 27 | } |
| 28 | } |