Passed
Push — master ( 700b0f...aafb0a )
by Björn
18:25 queued 10s
created

SettingsForm::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 101

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 101
ccs 0
cts 22
cp 0
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2

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
 * BB's Zend Framework 2 Components
4
 * 
5
 * AdminModule
6
 *
7
 * @package   [MyApplication]
8
 * @package   BB's Zend Framework 2 Components
9
 * @package   AdminModule
10
 * @author    Björn Bartels <[email protected]>
11
 * @link      https://gitlab.bjoernbartels.earth/groups/zf2
12
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
13
 * @copyright copyright (c) 2016 Björn Bartels <[email protected]>
14
 */
15
16
namespace Admin\Form;
17
18
use Zend\Form\Form;
19
use Admin\Module;
20
21
class SettingsForm extends Form
22
{
23
    public function __construct($name = null)
24
    {
25
        
26
        // we want to ignore the name passed
27
        parent::__construct('settings');
28
        $oModule = new Module();
29
        $cfg = $oModule->getConfig();
0 ignored issues
show
Unused Code introduced by
$cfg is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
30
        
31
        $this->setAttribute('method', 'post');
32
        $this->add(
33
            array(
34
            'name' => 'settings_id',
35
            'attributes' => array(
36
            'type'  => 'hidden',
37
            ),
38
            )
39
        );
40
        $this->add(
41
            array(
42
            'name' => 'scope',
43
            'attributes' => array(
44
            'type'  => 'text',
45
            ),
46
            'options' => array(
47
            'label' => 'scope',
48
            ),
49
            )
50
        );
51
        $this->add(
52
            array(
53
            'name' => 'ref_id',
54
            'attributes' => array(
55
            'type'  => 'text',
56
            ),
57
            'options' => array(
58
            'label' => 'reference',
59
            ),
60
            )
61
        );
62
        $this->add(
63
            array(
64
            'name' => 'type',
65
            'attributes' => array(
66
            'type'  => 'text',
67
            ),
68
            'options' => array(
69
            'label' => 'type',
70
            ),
71
            )
72
        );
73
        $this->add(
74
            array(
75
            'name' => 'name',
76
            'attributes' => array(
77
            'type'  => 'text',
78
            ),
79
            'options' => array(
80
            'label' => 'name',
81
            ),
82
            )
83
        );
84
        $this->add(
85
            array(
86
            'name' => 'value',
87
            'attributes' => array(
88
            'type'  => 'text',
89
            ),
90
            'options' => array(
91
            'label' => 'value',
92
            ),
93
            )
94
        );
95
        
96
        $this->add(
97
            array(
98
            'name' => 'submit',
99
            'attributes' => array(
100
            'type'  => 'submit',
101
            'value' => 'save',
102
            'id' => 'submitbutton',
103
            ),
104
            'options' => array(
105
            'label' => 'save',
106
            ),
107
            )
108
        );
109
        
110
        $this->add(
111
            array(
112
            'name' => 'reset',
113
            'attributes' => array(
114
            'type'  => 'reset',
115
            'value' => 'reset',
116
            'id' => 'resetbutton',
117
            ),
118
            'options' => array(
119
            'label' => 'reset',
120
            ),
121
            )
122
        );
123
    }
124
}