| Conditions | 1 |
| Paths | 1 |
| Total Lines | 60 |
| Code Lines | 50 |
| 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 |
||
| 49 | public function execute( $par ) { |
||
| 50 | $this->setHeaders(); |
||
| 51 | $this->outputHeader(); |
||
| 52 | $this->getOutput()->addModuleStyles( 'mediawiki.special.comparepages.styles' ); |
||
| 53 | |||
| 54 | $form = HTMLForm::factory( 'ooui', [ |
||
| 55 | 'Page1' => [ |
||
| 56 | 'type' => 'title', |
||
| 57 | 'name' => 'page1', |
||
| 58 | 'label-message' => 'compare-page1', |
||
| 59 | 'size' => '40', |
||
| 60 | 'section' => 'page1', |
||
| 61 | 'validation-callback' => [ $this, 'checkExistingTitle' ], |
||
| 62 | ], |
||
| 63 | 'Revision1' => [ |
||
| 64 | 'type' => 'int', |
||
| 65 | 'name' => 'rev1', |
||
| 66 | 'label-message' => 'compare-rev1', |
||
| 67 | 'size' => '8', |
||
| 68 | 'section' => 'page1', |
||
| 69 | 'validation-callback' => [ $this, 'checkExistingRevision' ], |
||
| 70 | ], |
||
| 71 | 'Page2' => [ |
||
| 72 | 'type' => 'title', |
||
| 73 | 'name' => 'page2', |
||
| 74 | 'label-message' => 'compare-page2', |
||
| 75 | 'size' => '40', |
||
| 76 | 'section' => 'page2', |
||
| 77 | 'validation-callback' => [ $this, 'checkExistingTitle' ], |
||
| 78 | ], |
||
| 79 | 'Revision2' => [ |
||
| 80 | 'type' => 'int', |
||
| 81 | 'name' => 'rev2', |
||
| 82 | 'label-message' => 'compare-rev2', |
||
| 83 | 'size' => '8', |
||
| 84 | 'section' => 'page2', |
||
| 85 | 'validation-callback' => [ $this, 'checkExistingRevision' ], |
||
| 86 | ], |
||
| 87 | 'Action' => [ |
||
| 88 | 'type' => 'hidden', |
||
| 89 | 'name' => 'action', |
||
| 90 | ], |
||
| 91 | 'Diffonly' => [ |
||
| 92 | 'type' => 'hidden', |
||
| 93 | 'name' => 'diffonly', |
||
| 94 | ], |
||
| 95 | 'Unhide' => [ |
||
| 96 | 'type' => 'hidden', |
||
| 97 | 'name' => 'unhide', |
||
| 98 | ], |
||
| 99 | ], $this->getContext(), 'compare' ); |
||
| 100 | $form->setSubmitTextMsg( 'compare-submit' ); |
||
| 101 | $form->suppressReset(); |
||
| 102 | $form->setMethod( 'get' ); |
||
| 103 | $form->setSubmitCallback( [ __CLASS__, 'showDiff' ] ); |
||
| 104 | |||
| 105 | $form->loadData(); |
||
| 106 | $form->displayForm( '' ); |
||
| 107 | $form->trySubmit(); |
||
| 108 | } |
||
| 109 | |||
| 175 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.