AbstractFormHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A process() 0 10 3
A getForm() 0 4 1
1
<?php
2
3
namespace Black\Common\Application\Form\Handler;
4
5
use Symfony\Component\Form\FormInterface;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
8
abstract class AbstractFormHandler implements HandlerInterface
9
{
10
    /**
11
     * @var \Symfony\Component\Form\FormInterface
12
     */
13
    protected $form;
14
15
    /**
16
     * @var null|\Symfony\Component\HttpFoundation\Request
17
     */
18
    protected $request;
19
20
    /**
21
     * @param FormInterface $form
22
     * @param RequestStack  $requestStack
23
     */
24
    public function __construct(
25
        FormInterface $form,
26
        RequestStack $requestStack
27
    ) {
28
        $this->form = $form;
29
        $this->request = $requestStack->getCurrentRequest();
30
    }
31
32
    /**
33
     * @return mixed
34
     */
35
    public function process()
36
    {
37
        if ('POST' === $this->request->getMethod()) {
38
            $this->form->handleRequest($this->request);
39
40
            if ($this->form->isValid()) {
41
                return $this->form->getData();
42
            }
43
        }
44
    }
45
46
    /**
47
     * @return FormInterface
48
     */
49
    public function getForm()
50
    {
51
        return $this->form;
52
    }
53
}
54