Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.67% covered (success)
91.67%
11 / 12
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
OneRecordHttpException
91.67% covered (success)
91.67%
11 / 12
75.00% covered (warning)
75.00%
3 / 4
6.02
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 isNotFound
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isForbidden
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isConflict
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\Client;
6
7use LambdaTwelve\OneRecord\Api\Error;
8use Psr\Http\Message\ResponseInterface;
9
10/**
11 * A 4xx or 5xx answer from a ONE Record server, with the api:Error document
12 * parsed when the server sent one.
13 */
14final class OneRecordHttpException extends ClientException
15{
16    public function __construct(
17        public readonly int $status,
18        public readonly ?Error $error,
19        public readonly ResponseInterface $response,
20        string $method,
21        string $url,
22    ) {
23        $detail = $error?->details[0]->message ?? null;
24        parent::__construct(\sprintf(
25            '%s %s answered %d%s%s',
26            $method,
27            $url,
28            $status,
29            $error !== null ? ': ' . $error->title : '',
30            $detail !== null ? ' (' . $detail . ')' : '',
31        ));
32    }
33
34    public function isNotFound(): bool
35    {
36        return $this->status === 404;
37    }
38
39    public function isForbidden(): bool
40    {
41        return $this->status === 403;
42    }
43
44    public function isConflict(): bool
45    {
46        return $this->status === 409;
47    }
48}