Conditions | 13 |
Paths | 1088 |
Total Lines | 76 |
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 |
||
136 | public static function prepareLink( $parser, $frame, $args ) { |
||
137 | |||
138 | global $wgSDImportDataPage; |
||
139 | |||
140 | $wgOut = $parser->getOutput(); |
||
141 | $wgOut->addModules( 'ext.sdimport' ); |
||
142 | |||
143 | $attrs_allowed = array( "title", "model", "readonly", "ref", "readOnlyfields" ); |
||
144 | |||
145 | $attrs = array(); |
||
146 | $output = ""; |
||
147 | $model = "json"; // Let's use by default JSON model |
||
148 | $pagetitle = null; // No page default. Do nothing |
||
149 | $ref = null; // No ref hash by default |
||
150 | $readOnlyfields = null; // No readonlyfields by default |
||
151 | |||
152 | foreach ( $args as $arg ) { |
||
153 | $arg_clean = trim( $frame->expand( $arg ) ); |
||
154 | $arg_proc = explode( "=", $arg_clean, 2 ); |
||
155 | |||
156 | if ( count( $arg_proc ) == 1 ){ |
||
157 | $pagetitle = trim( $arg_proc[0] ); |
||
158 | } else { |
||
159 | |||
160 | if ( in_array( trim( $arg_proc[0] ), $attrs_allowed ) ) { |
||
161 | $attrs[ trim( $arg_proc[0] ) ] = trim( $arg_proc[1] ); |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | |||
166 | // TODO: Parse more parameters from function |
||
167 | if ( array_key_exists( "title", $attrs ) ) { |
||
168 | $pagetitle = $attrs['title']; |
||
169 | } |
||
170 | if ( array_key_exists( "model", $attrs ) ) { |
||
171 | $model = $attrs['model']; |
||
172 | } |
||
173 | if ( array_key_exists( "ref", $attrs ) ) { |
||
174 | $ref = str_replace( "[", "{", $attrs['ref'] ); |
||
175 | $ref = str_replace( "]", "}", $ref ); |
||
176 | } |
||
177 | |||
178 | if ( array_key_exists( "readOnlyfields", $attrs ) ) { |
||
179 | $readOnlyfields = str_replace( "[", "{", $attrs['readOnlyfields'] ); |
||
180 | $readOnlyfields = str_replace( "]", "}", $readOnlyfields ); |
||
181 | } |
||
182 | |||
183 | if ( $pagetitle ) { |
||
184 | |||
185 | $dataAttrsStr = ""; |
||
186 | |||
187 | if ( $pagetitle ) { |
||
188 | $dataAttrsStr.= "data-title='$pagetitle'"; |
||
189 | } |
||
190 | |||
191 | if ( $ref ) { |
||
192 | $dataAttrsStr.= " data-ref='$ref'"; |
||
193 | } |
||
194 | |||
195 | if ( $readOnlyfields ) { |
||
196 | $dataAttrsStr.= " data-readOnlyfields='$readOnlyfields'"; |
||
197 | } |
||
198 | |||
199 | $dataAttrsStr.= " data-model='$model'"; |
||
200 | |||
201 | if ( array_key_exists( "readonly", $attrs ) ) { |
||
202 | $dataAttrsStr.= " data-readonly='true'"; |
||
203 | } |
||
204 | |||
205 | $output = "<div class='smwdata-link' ".$dataAttrsStr."></div>"; |
||
206 | |||
207 | } |
||
208 | |||
209 | return array( $output, 'noparse' => true, 'isHTML' => true ); |
||
210 | |||
211 | } |
||
212 | |||
236 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.