Completed
Pull Request — master (#21)
by steven
24:16 queued 14:46
created

AccountViewController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 1
A createRegisterForm() 0 12 1
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Account\Controllers;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\Form\FormInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\Translation\TranslatorInterface;
10
use VSV\GVQ_API\Account\Forms\RegistrationFormType;
11
12
class AccountViewController extends AbstractController
13
{
14
    /**
15
     * @var RegistrationFormType
16
     */
17
    private $registrationFormType;
18
19
    /**
20
     * @var TranslatorInterface
21
     */
22
    private $tranlator;
23
24
    /**
25
     * @param TranslatorInterface $translator
26
     */
27
    public function __construct(TranslatorInterface $translator)
28
    {
29
        $this->tranlator = $translator;
30
        $this->registrationFormType = new RegistrationFormType();
31
    }
32
33
    /**
34
     * @param Request $request
35
     * @return Response
36
     */
37
    public function register(Request $request): Response
38
    {
39
        $form = $this->createRegisterForm();
40
        $form->handleRequest($request);
41
42
        return $this->render(
43
            'accounts/register.html.twig',
44
            [
45
                'form' => $form->createView()
46
            ]
47
        );
48
    }
49
50
    /**
51
     * @return FormInterface
52
     */
53
    private function createRegisterForm(): FormInterface
54
    {
55
        $formBuilder = $this->createFormBuilder();
56
57
        $this->registrationFormType->buildForm(
58
          $formBuilder,
59
          [
60
              'translator' => $this->tranlator,
61
          ]
62
        );
63
64
        return $formBuilder->getForm();
65
    }
66
}
67