Conditions | 53 |
Paths | > 20000 |
Total Lines | 229 |
Code Lines | 163 |
Lines | 12 |
Ratio | 5.24 % |
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 |
||
237 | private function getModuleInfo( $module ) { |
||
238 | $ret = []; |
||
239 | $path = $module->getModulePath(); |
||
240 | |||
241 | $ret['name'] = $module->getModuleName(); |
||
242 | $ret['classname'] = get_class( $module ); |
||
243 | $ret['path'] = $path; |
||
244 | if ( !$module->isMain() ) { |
||
245 | $ret['group'] = $module->getParent()->getModuleManager()->getModuleGroup( |
||
246 | $module->getModuleName() |
||
247 | ); |
||
248 | } |
||
249 | $ret['prefix'] = $module->getModulePrefix(); |
||
250 | |||
251 | $sourceInfo = $module->getModuleSourceInfo(); |
||
252 | if ( $sourceInfo ) { |
||
253 | $ret['source'] = $sourceInfo['name']; |
||
254 | if ( isset( $sourceInfo['namemsg'] ) ) { |
||
255 | $ret['sourcename'] = $this->context->msg( $sourceInfo['namemsg'] )->text(); |
||
256 | } else { |
||
257 | $ret['sourcename'] = $ret['source']; |
||
258 | } |
||
259 | |||
260 | $link = SpecialPage::getTitleFor( 'Version', 'License/' . $sourceInfo['name'] )->getFullURL(); |
||
261 | if ( isset( $sourceInfo['license-name'] ) ) { |
||
262 | $ret['licensetag'] = $sourceInfo['license-name']; |
||
263 | $ret['licenselink'] = (string)$link; |
||
264 | } elseif ( SpecialVersion::getExtLicenseFileName( dirname( $sourceInfo['path'] ) ) ) { |
||
265 | $ret['licenselink'] = (string)$link; |
||
266 | } |
||
267 | } |
||
268 | |||
269 | $this->formatHelpMessages( $ret, 'description', $module->getFinalDescription() ); |
||
270 | |||
271 | foreach ( $module->getHelpFlags() as $flag ) { |
||
272 | $ret[$flag] = true; |
||
273 | } |
||
274 | |||
275 | $ret['helpurls'] = (array)$module->getHelpUrls(); |
||
276 | if ( isset( $ret['helpurls'][0] ) && $ret['helpurls'][0] === false ) { |
||
277 | $ret['helpurls'] = []; |
||
278 | } |
||
279 | ApiResult::setIndexedTagName( $ret['helpurls'], 'helpurl' ); |
||
280 | |||
281 | if ( $this->helpFormat !== 'none' ) { |
||
282 | $ret['examples'] = []; |
||
283 | $examples = $module->getExamplesMessages(); |
||
284 | foreach ( $examples as $qs => $msg ) { |
||
285 | $item = [ |
||
286 | 'query' => $qs |
||
287 | ]; |
||
288 | $msg = ApiBase::makeMessage( $msg, $this->context, [ |
||
289 | $module->getModulePrefix(), |
||
290 | $module->getModuleName(), |
||
291 | $module->getModulePath() |
||
292 | ] ); |
||
293 | $this->formatHelpMessages( $item, 'description', [ $msg ] ); |
||
294 | if ( isset( $item['description'] ) ) { |
||
295 | if ( is_array( $item['description'] ) ) { |
||
296 | $item['description'] = $item['description'][0]; |
||
297 | } else { |
||
298 | ApiResult::setSubelementsList( $item, 'description' ); |
||
299 | } |
||
300 | } |
||
301 | $ret['examples'][] = $item; |
||
302 | } |
||
303 | ApiResult::setIndexedTagName( $ret['examples'], 'example' ); |
||
304 | } |
||
305 | |||
306 | $ret['parameters'] = []; |
||
307 | $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP ); |
||
308 | $paramDesc = $module->getFinalParamDescription(); |
||
309 | foreach ( $params as $name => $settings ) { |
||
310 | if ( !is_array( $settings ) ) { |
||
311 | $settings = [ ApiBase::PARAM_DFLT => $settings ]; |
||
312 | } |
||
313 | |||
314 | $item = [ |
||
315 | 'name' => $name |
||
316 | ]; |
||
317 | if ( isset( $paramDesc[$name] ) ) { |
||
318 | $this->formatHelpMessages( $item, 'description', $paramDesc[$name], true ); |
||
319 | } |
||
320 | |||
321 | $item['required'] = !empty( $settings[ApiBase::PARAM_REQUIRED] ); |
||
322 | |||
323 | if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) { |
||
324 | $item['deprecated'] = true; |
||
325 | } |
||
326 | |||
327 | if ( $name === 'token' && $module->needsToken() ) { |
||
328 | $item['tokentype'] = $module->needsToken(); |
||
329 | } |
||
330 | |||
331 | View Code Duplication | if ( !isset( $settings[ApiBase::PARAM_TYPE] ) ) { |
|
332 | $dflt = isset( $settings[ApiBase::PARAM_DFLT] ) |
||
333 | ? $settings[ApiBase::PARAM_DFLT] |
||
334 | : null; |
||
335 | if ( is_bool( $dflt ) ) { |
||
336 | $settings[ApiBase::PARAM_TYPE] = 'boolean'; |
||
337 | } elseif ( is_string( $dflt ) || is_null( $dflt ) ) { |
||
338 | $settings[ApiBase::PARAM_TYPE] = 'string'; |
||
339 | } elseif ( is_int( $dflt ) ) { |
||
340 | $settings[ApiBase::PARAM_TYPE] = 'integer'; |
||
341 | } |
||
342 | } |
||
343 | |||
344 | if ( isset( $settings[ApiBase::PARAM_DFLT] ) ) { |
||
345 | switch ( $settings[ApiBase::PARAM_TYPE] ) { |
||
346 | case 'boolean': |
||
347 | $item['default'] = (bool)$settings[ApiBase::PARAM_DFLT]; |
||
348 | break; |
||
349 | case 'string': |
||
350 | case 'text': |
||
351 | case 'password': |
||
352 | $item['default'] = strval( $settings[ApiBase::PARAM_DFLT] ); |
||
353 | break; |
||
354 | case 'integer': |
||
355 | case 'limit': |
||
356 | $item['default'] = intval( $settings[ApiBase::PARAM_DFLT] ); |
||
357 | break; |
||
358 | case 'timestamp': |
||
359 | $item['default'] = wfTimestamp( TS_ISO_8601, $settings[ApiBase::PARAM_DFLT] ); |
||
360 | break; |
||
361 | default: |
||
362 | $item['default'] = $settings[ApiBase::PARAM_DFLT]; |
||
363 | break; |
||
364 | } |
||
365 | } |
||
366 | |||
367 | $item['multi'] = !empty( $settings[ApiBase::PARAM_ISMULTI] ); |
||
368 | if ( $item['multi'] ) { |
||
369 | $item['limit'] = $this->getMain()->canApiHighLimits() ? |
||
370 | ApiBase::LIMIT_SML2 : |
||
371 | ApiBase::LIMIT_SML1; |
||
372 | $item['lowlimit'] = ApiBase::LIMIT_SML1; |
||
373 | $item['highlimit'] = ApiBase::LIMIT_SML2; |
||
374 | } |
||
375 | |||
376 | if ( !empty( $settings[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) { |
||
377 | $item['allowsduplicates'] = true; |
||
378 | } |
||
379 | |||
380 | if ( isset( $settings[ApiBase::PARAM_TYPE] ) ) { |
||
381 | if ( $settings[ApiBase::PARAM_TYPE] === 'submodule' ) { |
||
382 | if ( isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) { |
||
383 | ksort( $settings[ApiBase::PARAM_SUBMODULE_MAP] ); |
||
384 | $item['type'] = array_keys( $settings[ApiBase::PARAM_SUBMODULE_MAP] ); |
||
385 | $item['submodules'] = $settings[ApiBase::PARAM_SUBMODULE_MAP]; |
||
386 | } else { |
||
387 | $item['type'] = $module->getModuleManager()->getNames( $name ); |
||
388 | sort( $item['type'] ); |
||
389 | $prefix = $module->isMain() |
||
390 | ? '' : ( $module->getModulePath() . '+' ); |
||
391 | $item['submodules'] = []; |
||
392 | foreach ( $item['type'] as $v ) { |
||
393 | $item['submodules'][$v] = $prefix . $v; |
||
394 | } |
||
395 | } |
||
396 | if ( isset( $settings[ApiBase::PARAM_SUBMODULE_PARAM_PREFIX] ) ) { |
||
397 | $item['submoduleparamprefix'] = $settings[ApiBase::PARAM_SUBMODULE_PARAM_PREFIX]; |
||
398 | } |
||
399 | } elseif ( $settings[ApiBase::PARAM_TYPE] === 'tags' ) { |
||
400 | $item['type'] = ChangeTags::listExplicitlyDefinedTags(); |
||
401 | } else { |
||
402 | $item['type'] = $settings[ApiBase::PARAM_TYPE]; |
||
403 | } |
||
404 | if ( is_array( $item['type'] ) ) { |
||
405 | // To prevent sparse arrays from being serialized to JSON as objects |
||
406 | $item['type'] = array_values( $item['type'] ); |
||
407 | ApiResult::setIndexedTagName( $item['type'], 't' ); |
||
408 | } |
||
409 | } |
||
410 | if ( isset( $settings[ApiBase::PARAM_MAX] ) ) { |
||
411 | $item['max'] = $settings[ApiBase::PARAM_MAX]; |
||
412 | } |
||
413 | if ( isset( $settings[ApiBase::PARAM_MAX2] ) ) { |
||
414 | $item['highmax'] = $settings[ApiBase::PARAM_MAX2]; |
||
415 | } |
||
416 | if ( isset( $settings[ApiBase::PARAM_MIN] ) ) { |
||
417 | $item['min'] = $settings[ApiBase::PARAM_MIN]; |
||
418 | } |
||
419 | if ( !empty( $settings[ApiBase::PARAM_RANGE_ENFORCE] ) ) { |
||
420 | $item['enforcerange'] = true; |
||
421 | } |
||
422 | |||
423 | if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) { |
||
424 | $item['info'] = []; |
||
425 | foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) { |
||
426 | $tag = array_shift( $i ); |
||
427 | $info = [ |
||
428 | 'name' => $tag, |
||
429 | ]; |
||
430 | if ( count( $i ) ) { |
||
431 | $info['values'] = $i; |
||
432 | ApiResult::setIndexedTagName( $info['values'], 'v' ); |
||
433 | } |
||
434 | $this->formatHelpMessages( $info, 'text', [ |
||
435 | $this->context->msg( "apihelp-{$path}-paraminfo-{$tag}" ) |
||
436 | ->numParams( count( $i ) ) |
||
437 | ->params( $this->context->getLanguage()->commaList( $i ) ) |
||
438 | ->params( $module->getModulePrefix() ) |
||
439 | ] ); |
||
440 | ApiResult::setSubelementsList( $info, 'text' ); |
||
441 | $item['info'][] = $info; |
||
442 | } |
||
443 | ApiResult::setIndexedTagName( $item['info'], 'i' ); |
||
444 | } |
||
445 | |||
446 | $ret['parameters'][] = $item; |
||
447 | } |
||
448 | ApiResult::setIndexedTagName( $ret['parameters'], 'param' ); |
||
449 | |||
450 | $dynamicParams = $module->dynamicParameterDocumentation(); |
||
451 | if ( $dynamicParams !== null ) { |
||
452 | if ( $this->helpFormat === 'none' ) { |
||
453 | $ret['dynamicparameters'] = true; |
||
454 | } else { |
||
455 | $dynamicParams = ApiBase::makeMessage( $dynamicParams, $this->context, [ |
||
456 | $module->getModulePrefix(), |
||
457 | $module->getModuleName(), |
||
458 | $module->getModulePath() |
||
459 | ] ); |
||
460 | $this->formatHelpMessages( $ret, 'dynamicparameters', [ $dynamicParams ] ); |
||
461 | } |
||
462 | } |
||
463 | |||
464 | return $ret; |
||
465 | } |
||
466 | |||
520 |