Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ChangeRejected
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\Change;
6
7use LambdaTwelve\OneRecord\Api\Error;
8use RuntimeException;
9
10/**
11 * A well-formed Change that cannot be applied: wrong revision, a value that
12 * is not there to delete, a property the class does not accept. The errors
13 * go on the ChangeRequest (api:hasError) with status REQUEST_FAILED, as the
14 * spec's asynchronous error handling describes.
15 */
16final class ChangeRejected extends RuntimeException
17{
18    /**
19     * @param non-empty-list<Error> $errors
20     */
21    public function __construct(public readonly array $errors)
22    {
23        parent::__construct(implode('; ', array_map(static fn(Error $e): string => $e->title . ($e->details !== [] && $e->details[0]->message !== null ? ': ' . $e->details[0]->message : ''), $errors)));
24    }
25}