| Conditions | 11 |
| Paths | 384 |
| Total Lines | 65 |
| Code Lines | 41 |
| 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 |
||
| 56 | function __construct( $siteName, $admin = null, array $option = [] ) { |
||
|
|
|||
| 57 | global $wgContLang; |
||
| 58 | |||
| 59 | parent::__construct(); |
||
| 60 | |||
| 61 | if ( isset( $option['scriptpath'] ) ) { |
||
| 62 | $this->specifiedScriptPath = true; |
||
| 63 | } |
||
| 64 | |||
| 65 | foreach ( $this->optionMap as $opt => $global ) { |
||
| 66 | if ( isset( $option[$opt] ) ) { |
||
| 67 | $GLOBALS[$global] = $option[$opt]; |
||
| 68 | $this->setVar( $global, $option[$opt] ); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | if ( isset( $option['lang'] ) ) { |
||
| 73 | global $wgLang, $wgLanguageCode; |
||
| 74 | $this->setVar( '_UserLang', $option['lang'] ); |
||
| 75 | $wgContLang = Language::factory( $option['lang'] ); |
||
| 76 | $wgLang = Language::factory( $option['lang'] ); |
||
| 77 | $wgLanguageCode = $option['lang']; |
||
| 78 | RequestContext::getMain()->setLanguage( $wgLang ); |
||
| 79 | } |
||
| 80 | |||
| 81 | $this->setVar( 'wgSitename', $siteName ); |
||
| 82 | |||
| 83 | $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) ); |
||
| 84 | if ( $metaNS == 'MediaWiki' ) { |
||
| 85 | $metaNS = 'Project'; |
||
| 86 | } |
||
| 87 | $this->setVar( 'wgMetaNamespace', $metaNS ); |
||
| 88 | |||
| 89 | if ( $admin ) { |
||
| 90 | $this->setVar( '_AdminName', $admin ); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ( !isset( $option['installdbuser'] ) ) { |
||
| 94 | $this->setVar( '_InstallUser', |
||
| 95 | $this->getVar( 'wgDBuser' ) ); |
||
| 96 | $this->setVar( '_InstallPassword', |
||
| 97 | $this->getVar( 'wgDBpassword' ) ); |
||
| 98 | } else { |
||
| 99 | $this->setVar( '_InstallUser', |
||
| 100 | $option['installdbuser'] ); |
||
| 101 | $this->setVar( '_InstallPassword', |
||
| 102 | isset( $option['installdbpass'] ) ? $option['installdbpass'] : "" ); |
||
| 103 | |||
| 104 | // Assume that if we're given the installer user, we'll create the account. |
||
| 105 | $this->setVar( '_CreateDBAccount', true ); |
||
| 106 | } |
||
| 107 | |||
| 108 | if ( isset( $option['pass'] ) ) { |
||
| 109 | $this->setVar( '_AdminPassword', $option['pass'] ); |
||
| 110 | } |
||
| 111 | |||
| 112 | // Set up the default skins |
||
| 113 | $skins = $this->findExtensions( 'skins' ); |
||
| 114 | $this->setVar( '_Skins', $skins ); |
||
| 115 | |||
| 116 | if ( $skins ) { |
||
| 117 | $skinNames = array_map( 'strtolower', $skins ); |
||
| 118 | $this->setVar( 'wgDefaultSkin', $this->getDefaultSkin( $skinNames ) ); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 226 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: