GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Form   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
C render() 0 40 7
A __invoke() 0 11 2
A setHorizontal() 0 12 4
A openTag() 0 6 1
1
<?php
2
3
/**
4
 * Form View Helper.
5
 *
6
 * This view helper overrides the default ZF2 helper to use the LosFormRow
7
 *
8
 * @author     Leandro Silva <[email protected]>
9
 *
10
 * @category   LosUi
11
 *
12
 * @license    https://github.com/Lansoweb/LosUi/blob/master/LICENSE MIT License
13
 *
14
 * @link       http://github.com/LansoWeb/LosUi
15
 * @link       http://getbootstrap.com/css/#forms
16
 */
17
namespace LosUi\Form\View\Helper;
18
19
use Zend\Form\FormInterface;
20
use Zend\Form\FieldsetInterface;
21
use Zend\Form\View\Helper\Form as ZfFormHelper;
22
use Zend\Form\Element\Button;
23
use Zend\Form\Element\Submit;
24
25
/**
26
 * Form View Helper.
27
 *
28
 * This view helper overrides the default ZF2 helper to use the LosFormRow
29
 *
30
 * @author     Leandro Silva <[email protected]>
31
 *
32
 * @category   LosUi
33
 *
34
 * @license    https://github.com/Lansoweb/LosUi/blob/master/LICENSE MIT License
35
 *
36
 * @link       http://github.com/LansoWeb/LosUi
37
 * @link       http://getbootstrap.com/css/#forms
38
 */
39
class Form extends ZfFormHelper
40
{
41
    protected $isHorizontal = false;
42
43
    protected $labelColumns = 2;
44
45
    /**
46
     * (non-PHPdoc).
47
     *
48
     * @see \Zend\Form\View\Helper\Form::render()
49
     */
50
    public function render(FormInterface $form, $isHorizontal = false, $labelColumns = 2)
51
    {
52
        $this->isHorizontal = (bool) $isHorizontal;
53
        $this->labelColumns = (int) $labelColumns;
54
55
        $this->setHorizontal($form, $this->isHorizontal);
56
57
        if (method_exists($form, 'prepare')) {
58
            $form->prepare();
59
        }
60
61
        $formContent = '';
62
63
        $buttons = [];
64
65
        foreach ($form as $element) {
66
            if ($element instanceof Button || $element instanceof Submit) {
67
                $buttons[] = $element;
68
                continue;
69
            } elseif ($element instanceof FieldsetInterface) {
70
                $formContent .= $this->view->plugin('losFormCollection')->render($element);
71
            } else {
72
                $formContent .= $this->view->plugin('losFormRow')->render(
73
                    $element,
74
                    $this->isHorizontal,
75
                    $this->labelColumns
76
                );
77
            }
78
        }
79
80
        if (count($buttons) > 0) {
81
            $formContent .= $this->view->plugin('losFormRow')->renderButtons(
82
                $buttons,
83
                $this->isHorizontal,
84
                $this->labelColumns
85
            );
86
        }
87
88
        return $this->openTag($form).$formContent.$this->closeTag();
89
    }
90
91
    /**
92
     * (non-PHPdoc).
93
     *
94
     * @see \Zend\Form\View\Helper\Form::__invoke()
95
     */
96
    public function __invoke(FormInterface $form = null, $isHorizontal = false, $labelColumns = 2)
97
    {
98
        $this->isHorizontal = (bool) $isHorizontal;
99
        $this->labelColumns = (int) $labelColumns;
100
101
        if (! $form) {
102
            return $this;
103
        }
104
105
        return $this->render($form, $this->isHorizontal, $this->labelColumns);
106
    }
107
108
    /**
109
     * @param FormInterface|null $form
110
     */
111
    private function setHorizontal($form, $isHorizontal = false)
112
    {
113
        $this->isHorizontal = (bool) $isHorizontal;
114
115
        if ($this->isHorizontal && $form !== null) {
116
            if ($form->hasAttribute('class')) {
117
                $form->setAttribute('class', 'form-horizontal '.$form->getAttribute('class'));
118
            } else {
119
                $form->setAttribute('class', 'form-horizontal');
120
            }
121
        }
122
    }
123
124
    public function openTag(FormInterface $form = null, $isHorizontal = false)
125
    {
126
        $this->setHorizontal($form, $isHorizontal);
127
128
        return parent::openTag($form);
129
    }
130
}
131