Passed
Push — feature/VSVGVQ-7 ( 2c37c2...dd7336 )
by steven
02:57
created

QuestionController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
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 QuestionRepository
15
     */
16
    private $questionRepository;
17
18
    /**
19
     * @var QuestionSerializer
20
     */
21
    private $questionSerializer;
22
23
    /**
24
     * @param QuestionRepository $questionRepository
25
     * @param QuestionSerializer $questionSerializer
26
     */
27
    public function __construct(
28
        QuestionRepository $questionRepository,
29
        QuestionSerializer $questionSerializer
30
    ) {
31
        $this->questionRepository = $questionRepository;
32
        $this->questionSerializer = $questionSerializer;
33
    }
34
35
    /**
36
     * @param Request $request
37
     * @return Response
38
     */
39
    public function save(Request $request): Response
40
    {
41
        $json = $request->getContent();
42
        /** @var Question $question */
43
        $question = $this->questionSerializer->deserialize($json, Question::class, 'json');
44
        $this->questionRepository->save($question);
45
46
        return new Response('Succeeded');
47
    }
48
}
49