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

RestResponse   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A noContent() 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
     * @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