CannotFormatJson::jsonError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\RestResource;
4
5
use Nette\InvalidArgumentException;
6
use Throwable;
7
use function sprintf;
8
9
final class CannotFormatJson extends InvalidArgumentException implements Unformattable
10
{
11
    public static function because(RestResource $resource, Throwable $reason): self
12
    {
13
        return new self(sprintf(
14
            'Could not format the resource `%s` as json, because: %s',
15
            $resource->name(),
16
            $reason->getMessage()
17
        ), $reason->getCode(), $reason);
18
    }
19
20
    public static function jsonError(RestResource $resource, string $error): self
21
    {
22
        return new self(sprintf(
23
            'Could not format the resource `%s` as json, because: %s',
24
            $resource->name(),
25
            $error
26
        ));
27
    }
28
}
29