Conditions | 2 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
74 | public static function getCommonParameters() { |
||
75 | global $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsMapWidth, $egMapsMapHeight, $egMapsDefaultService; |
||
76 | |||
77 | $params = []; |
||
78 | |||
79 | $params['mappingservice'] = [ |
||
80 | 'type' => 'mappingservice', |
||
81 | 'aliases' => 'service', |
||
82 | 'default' => $egMapsDefaultService, |
||
83 | ]; |
||
84 | |||
85 | $params['geoservice'] = [ |
||
86 | 'default' => $egMapsDefaultGeoService, |
||
87 | 'values' => $egMapsAvailableGeoServices, |
||
88 | 'dependencies' => 'mappingservice', |
||
89 | // TODO 'manipulations' => new MapsParamGeoService( 'mappingservice' ), |
||
90 | ]; |
||
91 | |||
92 | $params['width'] = [ |
||
93 | 'type' => 'dimension', |
||
94 | 'allowauto' => true, |
||
95 | 'units' => [ 'px', 'ex', 'em', '%', '' ], |
||
96 | 'default' => $egMapsMapWidth, |
||
97 | ]; |
||
98 | |||
99 | $params['height'] = [ |
||
100 | 'type' => 'dimension', |
||
101 | 'units' => [ 'px', 'ex', 'em', '' ], |
||
102 | 'default' => $egMapsMapHeight, |
||
103 | ]; |
||
104 | |||
105 | // TODO$manipulation = new MapsParamLocation(); |
||
106 | // TODO$manipulation->toJSONObj = true; |
||
107 | |||
108 | $params['centre'] = [ |
||
109 | 'type' => 'mapslocation', |
||
110 | 'aliases' => [ 'center' ], |
||
111 | 'default' => false, |
||
112 | 'manipulatedefault' => false, |
||
113 | ]; |
||
114 | |||
115 | // Give grep a chance to find the usages: |
||
116 | // maps-par-mappingservice, maps-par-geoservice, maps-par-width, |
||
117 | // maps-par-height, maps-par-centre |
||
118 | foreach ( $params as $name => &$data ) { |
||
119 | $data['name'] = $name; |
||
120 | $data['message'] = 'maps-par-' . $name; |
||
121 | } |
||
122 | |||
123 | return $params; |
||
124 | } |
||
125 | |||
176 |
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.