LogForm::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 3 Features 0
Metric Value
c 3
b 3
f 0
dl 0
loc 53
rs 9.5797
cc 1
eloc 37
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 LearnZF2Log\Form;
20
21
use Zend\Form\Form;
22
use Zend\InputFilter\InputFilterProviderInterface;
23
24
/**
25
 * @author Abdul Malik Ikhsan <[email protected]>
26
 */
27
class LogForm extends Form implements InputFilterProviderInterface
28
{
29
    public function init()
30
    {
31
        $this->add([
32
            'name' => 'logmessage',
33
            'type' => 'Textarea',
34
            'options' => [
35
                'label' => 'Log message',
36
            ],
37
            'attributes' => [
38
                'value' => 'this is log message',
39
            ],
40
        ]);
41
42
        $this->add([
43
            'name' => 'logpriority',
44
            'type' => 'Select',
45
            'options' => [
46
                'value_options' => [
47
                    0 => 'EMERG',
48
                    1 => 'ALERT',
49
                    2 => 'CRIT',
50
                    3 => 'ERR',
51
                    4 => 'WARN',
52
                    5 => 'NOTICE',
53
                    6 => 'INFO',
54
                    7 => 'DEBUG',
55
                ],
56
                'label' => 'Log priority',
57
            ],
58
        ]);
59
60
        $this->add([
61
            'name' => 'logformat',
62
            'type' => 'Select',
63
            'options' => [
64
                'value_options' => [
65
                    'simple' => 'Simple',
66
                    'xml' => 'Xml',
67
                ],
68
                'label' => 'Log format',
69
            ],
70
        ]);
71
72
        $this->add([
73
            'name' => 'submit',
74
            'attributes' => [
75
                'class' => 'form-control btn-primary',
76
                'type' => 'submit',
77
                'value' => 'Submit log data',
78
                'id' => 'submitbutton',
79
            ],
80
        ]);
81
    }
82
83
    public function getInputFilterSpecification()
84
    {
85
        return [
86
            [
87
                'name' => 'logmessage',
88
                'required' => true,
89
                'validators' => [
90
                    [
91
                        'name' => 'StringLength',
92
                        'options' => [
93
                            'encoding' => 'UTF-8',
94
                            'min' => 1,
95
                            'max' => 255,
96
                        ],
97
                    ],
98
                ],
99
            ],
100
        ];
101
    }
102
}
103