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

ApiResponseFactory::createResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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