Conditions | 3 |
Paths | 3 |
Total Lines | 95 |
Code Lines | 57 |
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 |
||
128 | private static function getEvenMawrCommonParameters() { |
||
129 | global $egMapsDefaultTitle, $egMapsDefaultLabel; |
||
130 | |||
131 | $params = []; |
||
132 | |||
133 | $params['title'] = [ |
||
134 | 'name' => 'title', |
||
135 | 'default' => $egMapsDefaultTitle, |
||
136 | ]; |
||
137 | |||
138 | $params['label'] = [ |
||
139 | 'default' => $egMapsDefaultLabel, |
||
140 | 'aliases' => 'text', |
||
141 | ]; |
||
142 | |||
143 | $params['icon'] = [ |
||
144 | 'default' => '', // TODO: image param |
||
145 | ]; |
||
146 | |||
147 | $params['visitedicon'] = [ |
||
148 | 'default' => '', //TODO: image param |
||
149 | ]; |
||
150 | |||
151 | $params['lines'] = [ |
||
152 | 'type' => 'mapsline', |
||
153 | 'default' => [], |
||
154 | 'delimiter' => ';', |
||
155 | 'islist' => true, |
||
156 | ]; |
||
157 | |||
158 | $params['polygons'] = [ |
||
159 | 'type' => 'mapspolygon', |
||
160 | 'default' => [], |
||
161 | 'delimiter' => ';', |
||
162 | 'islist' => true, |
||
163 | ]; |
||
164 | |||
165 | $params['circles'] = [ |
||
166 | 'type' => 'mapscircle', |
||
167 | 'default' => [], |
||
168 | 'delimiter' => ';', |
||
169 | 'islist' => true, |
||
170 | ]; |
||
171 | |||
172 | $params['rectangles'] = [ |
||
173 | 'type' => 'mapsrectangle', |
||
174 | 'default' => [], |
||
175 | 'delimiter' => ';', |
||
176 | 'islist' => true, |
||
177 | ]; |
||
178 | |||
179 | $params['wmsoverlay'] = [ |
||
180 | 'type' => 'wmsoverlay', |
||
181 | 'default' => false, |
||
182 | 'delimiter' => ' ', |
||
183 | ]; |
||
184 | |||
185 | $params['maxzoom'] = [ |
||
186 | 'type' => 'integer', |
||
187 | 'default' => false, |
||
188 | 'manipulatedefault' => false, |
||
189 | 'dependencies' => 'minzoom', |
||
190 | ]; |
||
191 | |||
192 | $params['minzoom'] = [ |
||
193 | 'type' => 'integer', |
||
194 | 'default' => false, |
||
195 | 'manipulatedefault' => false, |
||
196 | 'lowerbound' => 0, |
||
197 | ]; |
||
198 | |||
199 | $params['copycoords'] = [ |
||
200 | 'type' => 'boolean', |
||
201 | 'default' => false, |
||
202 | ]; |
||
203 | |||
204 | $params['static'] = [ |
||
205 | 'type' => 'boolean', |
||
206 | 'default' => false, |
||
207 | ]; |
||
208 | |||
209 | // Give grep a chance to find the usages: |
||
210 | // maps-displaymap-par-title, maps-displaymap-par-label, maps-displaymap-par-icon, |
||
211 | // maps-displaymap-par-visitedicon, aps-displaymap-par-lines, maps-displaymap-par-polygons, |
||
212 | // maps-displaymap-par-circles, maps-displaymap-par-rectangles, maps-displaymap-par-wmsoverlay, |
||
213 | // maps-displaymap-par-maxzoom, maps-displaymap-par-minzoom, maps-displaymap-par-copycoords, |
||
214 | // maps-displaymap-par-static |
||
215 | foreach ( $params as $name => &$param ) { |
||
216 | if ( !array_key_exists( 'message', $param ) ) { |
||
217 | $param['message'] = 'maps-displaymap-par-' . $name; |
||
218 | } |
||
219 | } |
||
220 | |||
221 | return $params; |
||
222 | } |
||
223 | |||
274 |
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.