CompanyController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A save() 0 15 1
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 Symfony\Component\Serializer\SerializerInterface;
8
use VSV\GVQ_API\Common\Serializers\JsonEnricher;
9
use VSV\GVQ_API\Company\Models\Company;
10
use VSV\GVQ_API\Company\Repositories\CompanyRepository;
11
12
class CompanyController
13
{
14
    /**
15
     * @var CompanyRepository
16
     */
17
    private $companyRepository;
18
19
    /**
20
     * @var SerializerInterface
21
     */
22
    private $serializer;
23
24
    /**
25
     * @var JsonEnricher
26
     */
27
    private $jsonEnricher;
28
29
    /**
30
     * @param CompanyRepository $companyRepository
31
     * @param SerializerInterface $companySerializer
32
     * @param JsonEnricher $jsonEnricher
33
     */
34
    public function __construct(
35
        CompanyRepository $companyRepository,
36
        SerializerInterface $companySerializer,
37
        JsonEnricher $jsonEnricher
38
    ) {
39
        $this->companyRepository = $companyRepository;
40
        $this->serializer = $companySerializer;
41
        $this->jsonEnricher = $jsonEnricher;
42
    }
43
44
    /**
45
     * @param Request $request
46
     * @return Response
47
     */
48
    public function save(Request $request): Response
49
    {
50
        /** @var string $json */
51
        $json = $request->getContent();
52
        $json = $this->jsonEnricher->enrich($json);
53
54
        /** @var Company $company */
55
        $company = $this->serializer->deserialize($json, Company::class, 'json');
56
57
        $this->companyRepository->save($company);
58
59
        $response = new Response('{"id":"'.$company->getId()->toString().'"}');
60
        $response->headers->set('Content-Type', 'application/json');
61
62
        return $response;
63
    }
64
}
65