AbstractFormHandler::doProcess()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
/*
4
 * This file is part of the MilioooMessageBundle package.
5
 *
6
 * (c) Michiel boeckaert <[email protected]>
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Miliooo\Messaging\Form\FormHandler;
12
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\Form\FormInterface;
15
16
/**
17
 * Description of AbstractFormHandler
18
 *
19
 * @author Michiel Boeckaert <[email protected]>
20
 */
21
abstract class AbstractFormHandler
22
{
23
    /**
24
     * The request the form will process
25
     *
26
     * @var Request
27
     */
28
    protected $request;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param Request $request The request the form will process
34
     */
35
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
36
    {
37
        $this->request = $request;
38
    }
39
40
    /**
41
     * Processes a form
42
     *
43
     * @param FormInterface $form The form we process
44
     *
45
     * @return boolean false if not processed true if processed
46
     */
47
    public function process(FormInterface $form)
0 ignored issues
show
Coding Style introduced by
function process() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
48
    {
49
        if ('POST' !== $this->request->getMethod()) {
50
            return false;
51
        }
52
53
        $form->handleRequest($this->request);
54
55
        if (!$form->isValid()) {
56
            return false;
57
        }
58
59
        $this->doProcess($form);
60
61
        return true;
62
    }
63
64
    /**
65
     * Do the processing of the valid form.
66
     *
67
     * @param FormInterface $form
68
     */
69
    abstract public function doProcess(FormInterface $form);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
70
}
71