Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ChangeFailed | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Server; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Api\ActionRequest; |
| 8 | use LambdaTwelve\OneRecord\Api\Error; |
| 9 | use RuntimeException; |
| 10 | |
| 11 | /** |
| 12 | * The holder's own change was accepted and could not be applied; no revision |
| 13 | * was written. Thrown from DataHolder::change(), update() and publish() so the |
| 14 | * caller, and its unit of work, see a failure instead of a request object to |
| 15 | * inspect. The request carried here is diagnostic: it was saved as |
| 16 | * REQUEST_FAILED inside the unit of work, so a transactional host rolls it |
| 17 | * back with everything else, while the identity unit of work keeps it. |
| 18 | */ |
| 19 | final class ChangeFailed extends RuntimeException |
| 20 | { |
| 21 | public function __construct(public readonly ActionRequest $request) |
| 22 | { |
| 23 | $reasons = implode('; ', array_map(static fn(Error $e): string => $e->title . (($e->details[0]->message ?? null) !== null ? ' (' . $e->details[0]->message . ')' : ''), $request->errors)); |
| 24 | parent::__construct(\sprintf( |
| 25 | 'The change to %s was not applied (%s): %s', |
| 26 | $request->logisticsObjects()[0]->value ?? 'the object', |
| 27 | $request->status->shortName(), |
| 28 | $reasons === '' ? 'no details recorded' : $reasons, |
| 29 | )); |
| 30 | } |
| 31 | } |