FormController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 3 Features 0
Metric Value
wmc 3
c 3
b 3
f 0
lcom 1
cbo 3
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A indexAction() 0 19 2
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the MIT license.
18
 */
19
namespace LearnZF2FormUsage\Controller;
20
21
use Zend\Form\FormInterface;
22
use Zend\Mvc\Controller\AbstractActionController;
23
use Zend\View\Model\ViewModel;
24
25
class FormController extends AbstractActionController
26
{
27
    /**
28
     * @var FormInterface
29
     */
30
    protected $form;
31
32
    /**
33
     * Construct form property.
34
     *
35
     * @param FormInterface $form
36
     */
37
    public function __construct(FormInterface $form)
38
    {
39
        $this->form = $form;
40
    }
41
42
    public function indexAction()
43
    {
44
        $request = $this->getRequest();
45
        $formMessages = [];
46
        $isPost = false;
47
48
        if ($request->isPost()) {
49
            $this->form->setData($request->getPost());
50
            $this->form->isValid();
51
            $formMessages = $this->form->getMessages();
52
            $isPost = true;
53
        }
54
55
        return new ViewModel([
56
            'form' => $this->form,
57
            'formMessages' => $formMessages,
58
            'isPost' => $isPost,
59
        ]);
60
    }
61
}
62