Conditions | 3 |
Paths | 3 |
Total Lines | 95 |
Lines | 0 |
Ratio | 0 % |
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 |
||
132 | private static function getEvenMawrCommonParameters() { |
||
133 | global $egMapsDefaultTitle, $egMapsDefaultLabel; |
||
134 | |||
135 | $params = []; |
||
136 | |||
137 | $params['title'] = [ |
||
138 | 'name' => 'title', |
||
139 | 'default' => $egMapsDefaultTitle, |
||
140 | ]; |
||
141 | |||
142 | $params['label'] = [ |
||
143 | 'default' => $egMapsDefaultLabel, |
||
144 | 'aliases' => 'text', |
||
145 | ]; |
||
146 | |||
147 | $params['icon'] = [ |
||
148 | 'default' => '', |
||
149 | ]; |
||
150 | |||
151 | $params['visitedicon'] = [ |
||
152 | 'default' => '', |
||
153 | ]; |
||
154 | |||
155 | $params['lines'] = [ |
||
156 | 'type' => 'mapsline', |
||
157 | 'default' => [], |
||
158 | 'delimiter' => ';', |
||
159 | 'islist' => true, |
||
160 | ]; |
||
161 | |||
162 | $params['polygons'] = [ |
||
163 | 'type' => 'mapspolygon', |
||
164 | 'default' => [], |
||
165 | 'delimiter' => ';', |
||
166 | 'islist' => true, |
||
167 | ]; |
||
168 | |||
169 | $params['circles'] = [ |
||
170 | 'type' => 'mapscircle', |
||
171 | 'default' => [], |
||
172 | 'delimiter' => ';', |
||
173 | 'islist' => true, |
||
174 | ]; |
||
175 | |||
176 | $params['rectangles'] = [ |
||
177 | 'type' => 'mapsrectangle', |
||
178 | 'default' => [], |
||
179 | 'delimiter' => ';', |
||
180 | 'islist' => true, |
||
181 | ]; |
||
182 | |||
183 | $params['wmsoverlay'] = [ |
||
184 | 'type' => 'wmsoverlay', |
||
185 | 'default' => false, |
||
186 | 'delimiter' => ' ', |
||
187 | ]; |
||
188 | |||
189 | $params['maxzoom'] = [ |
||
190 | 'type' => 'integer', |
||
191 | 'default' => false, |
||
192 | 'manipulatedefault' => false, |
||
193 | 'dependencies' => 'minzoom', |
||
194 | ]; |
||
195 | |||
196 | $params['minzoom'] = [ |
||
197 | 'type' => 'integer', |
||
198 | 'default' => false, |
||
199 | 'manipulatedefault' => false, |
||
200 | 'lowerbound' => 0, |
||
201 | ]; |
||
202 | |||
203 | $params['copycoords'] = [ |
||
204 | 'type' => 'boolean', |
||
205 | 'default' => false, |
||
206 | ]; |
||
207 | |||
208 | $params['static'] = [ |
||
209 | 'type' => 'boolean', |
||
210 | 'default' => false, |
||
211 | ]; |
||
212 | |||
213 | // Give grep a chance to find the usages: |
||
214 | // maps-displaymap-par-title, maps-displaymap-par-label, maps-displaymap-par-icon, |
||
215 | // maps-displaymap-par-visitedicon, aps-displaymap-par-lines, maps-displaymap-par-polygons, |
||
216 | // maps-displaymap-par-circles, maps-displaymap-par-rectangles, maps-displaymap-par-wmsoverlay, |
||
217 | // maps-displaymap-par-maxzoom, maps-displaymap-par-minzoom, maps-displaymap-par-copycoords, |
||
218 | // maps-displaymap-par-static |
||
219 | foreach ( $params as $name => &$param ) { |
||
220 | if ( !array_key_exists( 'message', $param ) ) { |
||
221 | $param['message'] = 'maps-displaymap-par-' . $name; |
||
222 | } |
||
223 | } |
||
224 | |||
225 | return $params; |
||
226 | } |
||
227 | |||
283 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.