| Conditions | 18 |
| Paths | 30 |
| Total Lines | 108 |
| 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 |
||
| 18 | public static function processData( $input, $args, $parser, $frame ) { |
||
|
|
|||
| 19 | |||
| 20 | global $wgSDImportDataPage; |
||
| 21 | $pageTitle = $parser->getTitle(); |
||
| 22 | $output = ""; |
||
| 23 | |||
| 24 | $separator="\t"; |
||
| 25 | $delimiter='"'; |
||
| 26 | $fields = array(); |
||
| 27 | |||
| 28 | if ( is_object( $pageTitle ) ) { |
||
| 29 | |||
| 30 | $ns = $pageTitle->getNamespace(); |
||
| 31 | |||
| 32 | if ( key_exists( $ns, $wgSDImportDataPage ) ) { |
||
| 33 | |||
| 34 | $nsRepo = $wgSDImportDataPage[$ns]; |
||
| 35 | |||
| 36 | $separator = SDImportData::getSelector( $args, $nsRepo, "separator" ); // String |
||
| 37 | $delimiter = SDImportData::getSelector( $args, $nsRepo, "delimiter" ); // String |
||
| 38 | $object = SDImportData::getSelector( $args, $nsRepo, "rowobject" ); // String |
||
| 39 | $fields = SDImportData::getSelector( $args, $nsRepo, "rowfields" ); // Array |
||
| 40 | $props = SDImportData::getSelector( $args, $nsRepo, "typefields" ); // Array |
||
| 41 | $refs = SDImportData::getSelector( $args, $nsRepo, "ref" ); // Hash |
||
| 42 | $pre = SDImportData::getSelector( $args, $nsRepo, "prefields" ); // Array |
||
| 43 | $post = SDImportData::getSelector( $args, $nsRepo, "postfields" ); // Array |
||
| 44 | $editable = SDImportData::getSelector( $args, $nsRepo, "edit" ); // Boolean |
||
| 45 | // TODO: Add single option here maybe? |
||
| 46 | |||
| 47 | // TODO: Should we add props here if they don't exist? |
||
| 48 | |||
| 49 | |||
| 50 | $dprops = array(); |
||
| 51 | |||
| 52 | if ( $refs ) { |
||
| 53 | foreach ( $refs as $key => $val ) { |
||
| 54 | $dprops[ $key ] = SDImportData::processWikiText( $val, $pageTitle ); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | // Empty array |
||
| 59 | $table = array(); |
||
| 60 | // We not assume preprocessing here |
||
| 61 | $checkstr = trim( $input ); |
||
| 62 | if ( !empty( $checkstr ) ) { |
||
| 63 | $table = self::getCSVData( $input, $separator, $delimiter ); |
||
| 64 | } |
||
| 65 | |||
| 66 | // wfErrorLog( "SELF: ".print_r($table), '/tmp/my-custom-debug.log' ); |
||
| 67 | |||
| 68 | |||
| 69 | foreach ( $table as $row ) { |
||
| 70 | $fieldcount = 0; |
||
| 71 | $struct = array(); |
||
| 72 | foreach ( $row as $field ) { |
||
| 73 | |||
| 74 | $field = trim( $field ); |
||
| 75 | |||
| 76 | if ( ! empty( $field ) ) { |
||
| 77 | $pretxt = ""; |
||
| 78 | if ( isset( $pre[ $fieldcount ] ) && !empty( $pre[ $fieldcount ] ) ) { |
||
| 79 | $pretxt = $pre[ $fieldcount ].":"; // : for pre |
||
| 80 | } |
||
| 81 | $postxt = ""; |
||
| 82 | if ( isset( $post[ $fieldcount ] ) && !empty( $post[ $fieldcount ] ) ) { |
||
| 83 | $postxt = "@".$post[ $fieldcount ]; // @ for post |
||
| 84 | } |
||
| 85 | if ( array_key_exists( $fieldcount, $fields ) ) { |
||
| 86 | $struct[ $fields[ $fieldcount ] ] = $pretxt.$field.$postxt; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | $fieldcount++; |
||
| 90 | } |
||
| 91 | foreach ( $dprops as $dpropk => $dpropv ) { |
||
| 92 | $struct[ $dpropk ] = $dpropv; |
||
| 93 | } |
||
| 94 | |||
| 95 | SDImportData::insertInternalObject( $parser, $pageTitle, $object, $struct ); |
||
| 96 | } |
||
| 97 | |||
| 98 | } |
||
| 99 | |||
| 100 | } |
||
| 101 | |||
| 102 | if ( !empty( $input ) ) { |
||
| 103 | $wgOut = $parser->getOutput(); |
||
| 104 | |||
| 105 | // TODO: Revisit if this still needs handled this way |
||
| 106 | global $wgScriptPath; |
||
| 107 | $handsonpath = $wgScriptPath."/extensions/SemanticDataImport/libs/handsontable/handsontable.full.js"; |
||
| 108 | $wgOut->addHeadItem( '<script src="'.$handsonpath.'"></script>' ); //Hack because of handsontable for last versions :/ |
||
| 109 | $wgOut->addModules( 'ext.sdimport' ); |
||
| 110 | |||
| 111 | $fieldList = ""; |
||
| 112 | if ( sizeof( $fields ) > 0 ) { |
||
| 113 | $fieldList = " data-cols='".implode(",", $fields)."' "; |
||
| 114 | } |
||
| 115 | |||
| 116 | $dataedit = ""; |
||
| 117 | if ( $editable ) { |
||
| 118 | $dataedit = "data-edit='data-edit'"; |
||
| 119 | } |
||
| 120 | |||
| 121 | $output = "<div class='smwdata' data-delimiter='".$delimiter."' data-separator=\"".$separator."\"".$fieldList." ".$dataedit.">".$input."</div>"; |
||
| 122 | } |
||
| 123 | |||
| 124 | return array( $output, 'noparse' => true, 'isHTML' => true ); |
||
| 125 | } |
||
| 126 | |||
| 236 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.