Completed
Push — master ( 6ebd1c...df9bae )
by John
10:14
created

ResponseFactory::createResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Response;
10
11
use KleijnWeb\SwaggerBundle\Document\DocumentRepository;
12
use KleijnWeb\SwaggerBundle\Serializer\SerializerAdapter;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpFoundation\Response;
15
16
/**
17
 * @author John Kleijn <[email protected]>
18
 */
19
class ResponseFactory
20
{
21
    /**
22
     * @var SerializerAdapter
23
     */
24
    private $serializer;
25
26
    /**
27
     * @var DocumentRepository
28
     */
29
    private $documentRepository;
30
31
    /**
32
     * @param DocumentRepository $documentRepository
33
     * @param SerializerAdapter  $serializer
34
     */
35
    public function __construct(DocumentRepository $documentRepository, SerializerAdapter $serializer)
36
    {
37
        $this->serializer = $serializer;
38
        $this->documentRepository = $documentRepository;
39
    }
40
41
    /**
42
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
43
     *
44
     * @param Request $request
45
     * @param mixed   $data
46
     *
47
     * @return Response
48
     */
49
    public function createResponse(Request $request, $data)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        $headers = ['Content-Type' => 'application/json'];
52
53
        if ($data === null) {
54
            return new Response('', 204, $headers);
55
        }
56
        $data = $this->serializer->serialize($data, 'json');
57
58
        return new Response($data, 200, $headers);
59
    }
60
}
61