Passed
Push — feature/uploadable ( 7c6d25...a7ed20 )
by Daniel
11:07
created

FormPostPatchAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 17
ccs 0
cts 9
cp 0
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Action\Form;
15
16
use Silverback\ApiComponentsBundle\Action\AbstractAction;
17
use Silverback\ApiComponentsBundle\Entity\Component\Form;
18
use Silverback\ApiComponentsBundle\Factory\Response\ResponseFactory;
19
use Silverback\ApiComponentsBundle\Form\Handler\FormSubmitHandler;
20
use Silverback\ApiComponentsBundle\Serializer\SerializeFormatResolver;
21
use Symfony\Component\HttpFoundation\Request;
22
use Symfony\Component\Serializer\SerializerInterface;
23
24
/**
25
 * @author Daniel West <[email protected]>
26
 */
27
class FormPostPatchAction extends AbstractAction
28
{
29
    private FormSubmitHandler $formSubmitHandler;
30
31
    public function __construct(SerializerInterface $serializer, SerializeFormatResolver $requestFormatResolver, ResponseFactory $responseFactory, FormSubmitHandler $formSubmitHandler)
32
    {
33
        parent::__construct($serializer, $requestFormatResolver, $responseFactory);
34
        $this->formSubmitHandler = $formSubmitHandler;
35
    }
36
37
    public function __invoke(Request $request, Form $data)
38
    {
39
        $decodedContent = $this->serializer->decode($request->getContent(), $this->requestFormatResolver->getFormatFromRequest($request), []);
40
        $isPatchRequest = Request::METHOD_PATCH === $request->getMethod();
41
        $response = $this->formSubmitHandler->handle($decodedContent, $isPatchRequest, $data, $this->requestFormatResolver->getFormatFromRequest($request));
42
43
        return $this->responseFactory->create($request, $response->getContent(), $response->getStatusCode());
44
    }
45
}
46