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

RestResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 31
ccs 5
cts 8
cp 0.625
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A noContent() 0 3 1
A createForbidden() 0 3 1
A exception() 0 7 2
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