| Conditions | 8 |
| Paths | 7 |
| Total Lines | 54 |
| Code Lines | 27 |
| 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 |
||
| 34 | public function execute() { |
||
|
|
|||
| 35 | if ( $this->getVar( '_UpgradeDone' ) ) { |
||
| 36 | // Allow regeneration of LocalSettings.php, unless we are working |
||
| 37 | // from a pre-existing LocalSettings.php file and we want to avoid |
||
| 38 | // leaking its contents |
||
| 39 | if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) { |
||
| 40 | // Done message acknowledged |
||
| 41 | return 'continue'; |
||
| 42 | } else { |
||
| 43 | // Back button click |
||
| 44 | // Show the done message again |
||
| 45 | // Make them click back again if they want to do the upgrade again |
||
| 46 | $this->showDoneMessage(); |
||
| 47 | |||
| 48 | return 'output'; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | // wgDBtype is generally valid here because otherwise the previous page |
||
| 53 | // (connect) wouldn't have declared its happiness |
||
| 54 | $type = $this->getVar( 'wgDBtype' ); |
||
| 55 | $installer = $this->parent->getDBInstaller( $type ); |
||
| 56 | |||
| 57 | if ( !$installer->needsUpgrade() ) { |
||
| 58 | return 'skip'; |
||
| 59 | } |
||
| 60 | |||
| 61 | if ( $this->parent->request->wasPosted() ) { |
||
| 62 | $installer->preUpgrade(); |
||
| 63 | |||
| 64 | $this->startLiveBox(); |
||
| 65 | $result = $installer->doUpgrade(); |
||
| 66 | $this->endLiveBox(); |
||
| 67 | |||
| 68 | if ( $result ) { |
||
| 69 | // If they're going to possibly regenerate LocalSettings, we |
||
| 70 | // need to create the upgrade/secret keys. Bug 26481 |
||
| 71 | if ( !$this->getVar( '_ExistingDBSettings' ) ) { |
||
| 72 | $this->parent->generateKeys(); |
||
| 73 | } |
||
| 74 | $this->setVar( '_UpgradeDone', true ); |
||
| 75 | $this->showDoneMessage(); |
||
| 76 | |||
| 77 | return 'output'; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | $this->startForm(); |
||
| 82 | $this->addHTML( $this->parent->getInfoBox( |
||
| 83 | wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) ); |
||
| 84 | $this->endForm(); |
||
| 85 | |||
| 86 | return null; |
||
| 87 | } |
||
| 88 | |||
| 111 |
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: