CannotFormatJson   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonError() 0 6 1
A because() 0 7 1
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