Completed
Push — master ( f11392...85f8c7 )
by Pavel
01:55 queued 18s
created

RestResponse::exception()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Pz\Doctrine\Rest;
2
3
use Pz\Doctrine\Rest\Exceptions\RestException;
4
use Symfony\Component\HttpFoundation\JsonResponse;
5
6
class RestResponse extends JsonResponse
7
{
8
    /**
9
     * @return static
10
     */
11 1
    public static function noContent()
12
    {
13 1
        return static::create(null, static::HTTP_NO_CONTENT);
14
    }
15
16
    /**
17
     * @param \Error|\Exception|RestException $exception
18
     *
19
     * @return RestResponse
20
     * @throws \Error|\Exception|RestException
21
     */
22 2
    public static function exception(\Exception $exception)
23
    {
24 2
        if (!$exception instanceof RestException) {
25
            $exception = RestException::createFromException($exception);
26
        }
27
28 2
        return RestResponse::create(['errors' => $exception->errors()], $exception->getCode());
29
    }
30
}
31