| Conditions | 18 |
| Paths | 192 |
| Total Lines | 74 |
| Code Lines | 44 |
| 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 |
||
| 59 | public function execute() { |
||
| 60 | // @codingStandardsIgnoreStart Ignore error: Global variable "$mmfl" is lacking 'wg' prefix |
||
| 61 | global $mmfl; |
||
| 62 | // @codingStandardsIgnoreEnd |
||
| 63 | global $wgExtensionEntryPointListFiles; |
||
| 64 | |||
| 65 | if ( !count( $wgExtensionEntryPointListFiles ) |
||
| 66 | && !$this->hasOption( 'list-file' ) |
||
| 67 | && !$this->hasOption( 'extensions-dir' ) |
||
| 68 | ) { |
||
| 69 | $this->error( "Either --list-file or --extensions-dir must be provided if " . |
||
| 70 | "\$wgExtensionEntryPointListFiles is not set", 1 ); |
||
| 71 | } |
||
| 72 | |||
| 73 | $mmfl = [ 'setupFiles' => [] ]; |
||
| 74 | |||
| 75 | # Add setup files contained in file passed to --list-file |
||
| 76 | if ( $this->hasOption( 'list-file' ) ) { |
||
| 77 | $extensionPaths = $this->readFile( $this->getOption( 'list-file' ) ); |
||
| 78 | $mmfl['setupFiles'] = array_merge( $mmfl['setupFiles'], $extensionPaths ); |
||
| 79 | } |
||
| 80 | |||
| 81 | # Now find out files in a directory |
||
| 82 | if ( $this->hasOption( 'extensions-dir' ) ) { |
||
| 83 | $extdir = $this->getOption( 'extensions-dir' ); |
||
| 84 | # Allow multiple directories to be passed with ":" as delimiter |
||
| 85 | $extdirs = explode( ':', $extdir ); |
||
| 86 | $entries = []; |
||
| 87 | foreach ( $extdirs as $extdir ) { |
||
| 88 | $entries = array_merge( $entries, scandir( $extdir ) ); |
||
| 89 | } |
||
| 90 | foreach ( $entries as $extname ) { |
||
| 91 | if ( $extname == '.' || $extname == '..' || !is_dir( "$extdir/$extname" ) ) { |
||
| 92 | continue; |
||
| 93 | } |
||
| 94 | $possibilities = [ |
||
| 95 | "$extdir/$extname/extension.json", |
||
| 96 | "$extdir/$extname/skin.json", |
||
| 97 | "$extdir/$extname/$extname.php" |
||
| 98 | ]; |
||
| 99 | $found = false; |
||
| 100 | foreach ( $possibilities as $extfile ) { |
||
| 101 | if ( file_exists( $extfile ) ) { |
||
| 102 | $mmfl['setupFiles'][] = $extfile; |
||
| 103 | $found = true; |
||
| 104 | break; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | if ( !$found ) { |
||
| 109 | $this->hasError = true; |
||
| 110 | $this->error( "Extension {$extname} in {$extdir} lacks expected entry point: " . |
||
| 111 | "extension.json, skin.json, or {$extname}.php." ); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | # Add setup files defined via configuration |
||
| 117 | foreach ( $wgExtensionEntryPointListFiles as $points ) { |
||
| 118 | $extensionPaths = $this->readFile( $points ); |
||
| 119 | $mmfl['setupFiles'] = array_merge( $mmfl['setupFiles'], $extensionPaths ); |
||
| 120 | } |
||
| 121 | |||
| 122 | if ( $this->hasError ) { |
||
| 123 | $this->error( "Some files are missing (see above). Giving up.", 1 ); |
||
| 124 | } |
||
| 125 | |||
| 126 | if ( $this->hasOption( 'output' ) ) { |
||
| 127 | $mmfl['output'] = $this->getOption( 'output' ); |
||
| 128 | } |
||
| 129 | if ( $this->hasOption( 'quiet' ) ) { |
||
| 130 | $mmfl['quiet'] = true; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 220 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.