| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| 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 |
||
| 41 | public function execute($par) { |
||
| 42 | global $wgOut; |
||
| 43 | |||
| 44 | global $wgSDImportDataPage; // Configuration options |
||
| 45 | |||
| 46 | $list_namespaces = self::getKeyOptionsWithBlank( array_keys( $wgSDImportDataPage ) ); |
||
| 47 | |||
| 48 | $wgOut->addModules( 'ext.sdimport' ); |
||
| 49 | $this->setHeaders(); |
||
| 50 | |||
| 51 | // TODO: We should handle request in the form in a better way. $wgRequest Check examples here: involved http://www.mediawiki.org/wiki/Category:Special_page_extensions |
||
| 52 | |||
| 53 | # A formDescriptor for uploading stuff |
||
| 54 | $formDescriptor = array( |
||
| 55 | |||
| 56 | 'fileupload' => array( |
||
| 57 | 'section' => 'upload', |
||
| 58 | 'label' => 'Upload file', |
||
| 59 | 'class' => 'HTMLTextField', |
||
| 60 | 'type' => 'file' |
||
| 61 | ), |
||
| 62 | 'separator' => array( |
||
| 63 | 'section' => 'upload', |
||
| 64 | 'type' => 'select', |
||
| 65 | 'label' => 'Separator', |
||
| 66 | 'options' => array( "," => ",","{TAB}" => "{TAB}", ";" => ";" ) |
||
| 67 | ), |
||
| 68 | 'delimiter' => array( |
||
| 69 | 'section' => 'upload', |
||
| 70 | 'type' => 'select', |
||
| 71 | 'label' => 'Delimiter', |
||
| 72 | 'options' => array( "\"" => "\"" , "'" => "'" ) |
||
| 73 | ), |
||
| 74 | 'namespace' => array( |
||
| 75 | 'section' => 'upload', |
||
| 76 | 'type' => 'select', |
||
| 77 | 'label' => 'Namespace', |
||
| 78 | 'options' => $list_namespaces |
||
| 79 | ), |
||
| 80 | 'single' => [ |
||
| 81 | 'section' => 'upload', |
||
| 82 | 'class' => 'HTMLCheckField', |
||
| 83 | 'label' => 'Single row mode', |
||
| 84 | 'default' => false, |
||
| 85 | ] |
||
| 86 | |||
| 87 | ); |
||
| 88 | |||
| 89 | |||
| 90 | $htmlForm = new HTMLForm( $formDescriptor, 'sdimport-form' ); |
||
| 91 | |||
| 92 | $htmlForm->setSubmitText( wfMessage('sdimport-form-submit-button')->text() ); # What text does the submit button display |
||
| 93 | $htmlForm->setTitle( $this->getTitle() ); # You must call setTitle() on an HTMLForm |
||
| 94 | |||
| 95 | /* We set a callback function */ |
||
| 96 | $htmlForm->setSubmitCallback( array( 'SpecialSDImport', 'processCSV' ) ); |
||
| 97 | |||
| 98 | $htmlForm->suppressReset(false); # Get back reset button |
||
| 99 | |||
| 100 | $wgOut->addHTML( "<div id='sdintro' class='sdimport_section'>" ); |
||
| 101 | $wgOut->addHTML( wfMessage('sdimport-form-intro')->text() ); |
||
| 102 | $wgOut->addHTML( "</div>" ); |
||
| 103 | $wgOut->addHTML( "<div id='sdform' class='sdimport_section'>" ); |
||
| 104 | $htmlForm->show(); # Displaying the form |
||
| 105 | $wgOut->addHTML( "</div>" ); |
||
| 106 | $wgOut->addHTML( "<div id='sdpreview' class='hot handsontable htColumnHeaders sdimport_section'></div>" ); |
||
| 107 | //$wgOut->addHTML( "<div id='sdpreview' class='hot handsontable htColumnHeaders'></div>"); |
||
| 108 | } |
||
| 109 | |||
| 118 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.