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

RestResponse::noContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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