Conditions | 1 |
Paths | 1 |
Total Lines | 125 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 2 |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | public function __construct($name = null) |
||
24 | { |
||
25 | |||
26 | // we want to ignore the name passed |
||
27 | parent::__construct('clients'); |
||
28 | $oModule = new Module(); |
||
29 | $cfg = $oModule->getConfig(); |
||
|
|||
30 | |||
31 | $this->setAttribute('method', 'post'); |
||
32 | $this->add( |
||
33 | array( |
||
34 | 'name' => 'clients_id', |
||
35 | 'attributes' => array( |
||
36 | 'type' => 'hidden', |
||
37 | ), |
||
38 | ) |
||
39 | ); |
||
40 | $this->add( |
||
41 | array( |
||
42 | 'name' => 'name', |
||
43 | 'attributes' => array( |
||
44 | 'type' => 'text', |
||
45 | ), |
||
46 | 'options' => array( |
||
47 | 'label' => 'name', |
||
48 | ), |
||
49 | ) |
||
50 | ); |
||
51 | $this->add( |
||
52 | array( |
||
53 | 'name' => 'extraname', |
||
54 | 'attributes' => array( |
||
55 | 'type' => 'text', |
||
56 | ), |
||
57 | 'options' => array( |
||
58 | 'label' => 'extraname', |
||
59 | ), |
||
60 | ) |
||
61 | ); |
||
62 | $this->add( |
||
63 | array( |
||
64 | 'name' => 'homepage', |
||
65 | 'type' => 'url', |
||
66 | 'attributes' => array( |
||
67 | 'type' => 'url', |
||
68 | ), |
||
69 | 'options' => array( |
||
70 | 'label' => 'homepage', |
||
71 | ), |
||
72 | ) |
||
73 | ); |
||
74 | $this->add( |
||
75 | array( |
||
76 | 'name' => 'email', |
||
77 | 'type' => 'email', |
||
78 | 'attributes' => array( |
||
79 | 'type' => 'email', |
||
80 | ), |
||
81 | 'options' => array( |
||
82 | 'label' => 'email', |
||
83 | ), |
||
84 | ) |
||
85 | ); |
||
86 | $this->add( |
||
87 | array( |
||
88 | 'name' => 'contact', |
||
89 | 'attributes' => array( |
||
90 | 'type' => 'text', |
||
91 | ), |
||
92 | 'options' => array( |
||
93 | 'label' => 'contact', |
||
94 | ), |
||
95 | ) |
||
96 | ); |
||
97 | $this->add( |
||
98 | array( |
||
99 | 'name' => 'phone', |
||
100 | 'attributes' => array( |
||
101 | 'type' => 'text', |
||
102 | ), |
||
103 | 'options' => array( |
||
104 | 'label' => 'phone', |
||
105 | ), |
||
106 | ) |
||
107 | ); |
||
108 | $this->add( |
||
109 | array( |
||
110 | 'name' => 'statistics', |
||
111 | 'attributes' => array( |
||
112 | 'type' => 'text', |
||
113 | ), |
||
114 | 'options' => array( |
||
115 | 'label' => 'statistics', |
||
116 | ), |
||
117 | ) |
||
118 | ); |
||
119 | |||
120 | $this->add( |
||
121 | array( |
||
122 | 'name' => 'submit', |
||
123 | 'attributes' => array( |
||
124 | 'type' => 'submit', |
||
125 | 'value' => 'save', |
||
126 | 'id' => 'submitbutton', |
||
127 | ), |
||
128 | 'options' => array( |
||
129 | 'label' => 'save', |
||
130 | ), |
||
131 | ) |
||
132 | ); |
||
133 | |||
134 | $this->add( |
||
135 | array( |
||
136 | 'name' => 'reset', |
||
137 | 'attributes' => array( |
||
138 | 'type' => 'reset', |
||
139 | 'value' => 'reset', |
||
140 | 'id' => 'resetbutton', |
||
141 | ), |
||
142 | 'options' => array( |
||
143 | 'label' => 'reset', |
||
144 | ), |
||
145 | ) |
||
146 | ); |
||
147 | } |
||
148 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.