FormAction::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 2
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Controller;
6
7
use App\Dto\RegisterFormDto;
8
use App\Form\Type\RegisterForm;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\Routing\Attribute\Route;
13
14
/**
15
 * @see FormActionTest
16
 */
17
final class FormAction extends AbstractController
18
{
19
    /**
20
     * A simple form.
21
     */
22 3
    #[Route(path: '/form', name: self::class)]
23
    public function __invoke(Request $request): Response
24
    {
25 3
        $dto = new RegisterFormDto();
26 3
        $form = $this->createForm(RegisterForm::class, $dto)->handleRequest($request);
27 3
        if ($form->isSubmitted() && $form->isValid()) {
28
            // just for the example, the DTO has already been updated at this point
29 1
            $dto = $form->getData();
30
        }
31
32 3
        return $this->render(self::class.'.html.twig', [
33 3
            'form' => $form,
34 3
            'dto' => $dto,
35 3
        ]);
36
    }
37
}
38