Passed
Push — feature/VSVGVQ-7-Route ( 39596e )
by Luc
03:10
created

QuestionController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getById() 0 3 1
A getAll() 0 3 1
A __construct() 0 6 1
A create() 0 15 1
1
<?php
2
3
namespace VSV\GVQ_API\Question\Controllers;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use VSV\GVQ_API\Question\Models\Question;
8
use VSV\GVQ_API\Question\Repositories\QuestionRepository;
9
use VSV\GVQ_API\Question\Serializers\QuestionSerializer;
10
11
class QuestionController
12
{
13
    /**
14
     * @var QuestionSerializer
15
     */
16
    private $questionSerializer;
17
18
    /**
19
     * @var QuestionRepository
20
     */
21
    private $questionRepository;
22
23
    /**
24
     * @param QuestionSerializer $questionSerializer
25
     * @param QuestionRepository $questionRepository
26
     */
27
    public function __construct(
28
        QuestionSerializer $questionSerializer,
29
        QuestionRepository $questionRepository
30
    ) {
31
        $this->questionSerializer = $questionSerializer;
32
        $this->questionRepository = $questionRepository;
33
    }
34
35
    /**
36
     * @param Request $request
37
     * @return Response
38
     */
39
    public function create(Request $request): Response
40
    {
41
        // @todo: check for missing id
42
        $json = $request->getContent();
43
44
        /** @var Question $question */
45
        $question = $this->questionSerializer->deserialize(
46
            $json,
47
            Question::class,
48
            'json'
49
        );
50
51
        $this->questionRepository->save($question);
52
53
        return new Response('QUESTION CREATED');
54
    }
55
56
    public function getAll(Request $request): Response
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

56
    public function getAll(/** @scrutinizer ignore-unused */ Request $request): Response

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

Loading history...
57
    {
58
        return new Response('GETALL');
59
    }
60
61
    public function getById(Request $request, string $id): Response
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function getById(Request $request, /** @scrutinizer ignore-unused */ string $id): Response

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

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function getById(/** @scrutinizer ignore-unused */ Request $request, string $id): Response

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

Loading history...
62
    {
63
        return new Response('GETBYID');
64
    }
65
}
66