Passed
Push — master ( 90db0f...396226 )
by Jafar
03:16
created

ApiResponseFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createResponse() 0 10 2
1
<?php
2
/*
3
 * This file is part of the Guarded Authentication package.
4
 *
5
 * (c) Jafar Jabr <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Jafar\Bundle\GuardedAuthenticationBundle\Api\ApiResponse;
12
13
use Symfony\Component\HttpFoundation\JsonResponse;
14
15
/**
16
 * Class ApiResponseFactory.
17
 *
18
 * @author Jafar Jabr <[email protected]>
19
 */
20
final class ApiResponseFactory
21
{
22
    public function createResponse(ApiProblem $apiProblem)
23
    {
24
        $data = $apiProblem->toArray();
25
        if ('about:blank' != $data['type']) {
26
            $data['type'] = 'http://localhost/just_url/web/errors#'.$data['type'];
27
        }
28
        $response = new JsonResponse($data, $apiProblem->getStatusCode());
29
        $response->headers->set('Content-Type', 'application/problem+json');
30
31
        return $response;
32
    }
33
}
34