Completed
Push — feature/VSVGVQ-20 ( 30ada6...30ada6 )
by steven
02:59
created

CompanyController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Company\Controllers;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use VSV\GVQ_API\Company\Models\Company;
8
use VSV\GVQ_API\Company\Repositories\CompanyRepository;
9
use VSV\GVQ_API\Company\Serializers\CompanySerializer;
10
11
class CompanyController
12
{
13
    /**
14
     * @var CompanyRepository
15
     */
16
    private $companyRepository;
17
18
    /**
19
     * @var CompanySerializer
20
     */
21
    private $companySerlializer;
22
23
    /**
24
     * @param CompanyRepository $companyRepository
25
     * @param CompanySerializer $companySerlializer
26
     */
27
    public function __construct(CompanyRepository $companyRepository, CompanySerializer $companySerlializer)
28
    {
29
        $this->companyRepository = $companyRepository;
30
        $this->companySerlializer = $companySerlializer;
31
    }
32
33
    /**
34
     * @param Request $request
35
     * @return Response
36
     */
37
    public function save(Request $request): Response
38
    {
39
        $json = $request->getContent();
40
        /** @var Company $company */
41
        $company = $this->companySerlializer->deserialize($json, Company::class, 'json');
42
        $this->companyRepository->save($company);
43
44
        $response = new Response('{"id":"'.$company->getId()->toString().'"}');
45
        $response->headers->set('Content-Type', 'application/json');
46
47
        return $response;
48
    }
49
}
50