Passed
Push — master ( 104bbb...1b0f3f )
by Pavel
01:40
created

RestResponse::createForbidden()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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
     * @return static
18
     */
19
    public static function createForbidden()
20
    {
21
        return static::create(null, static::HTTP_FORBIDDEN);
22
    }
23
24
    /**
25
     * @param \Error|\Exception|RestException $exception
26
     *
27
     * @return RestResponse
28
     * @throws \Error|\Exception|RestException
29
     */
30 2
    public static function exception(\Exception $exception)
31
    {
32 2
        if (!$exception instanceof RestException) {
33
            $exception = RestException::createFromException($exception);
34
        }
35
36 2
        return RestResponse::create(['errors' => $exception->errors()], $exception->getCode());
37
    }
38
}
39