| Conditions | 9 |
| Paths | 31 |
| Total Lines | 53 |
| 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 | |||
| 36 | if ( !defined( 'SMW_VERSION' ) || !$GLOBALS['smwgSemanticsEnabled'] ) { |
||
| 37 | |||
| 38 | $this->reportMessage( "\nYou need to have SMW enabled in order to run this maintenance script!\n" ); |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | $ns = $this->getOption( "namespace", null ); |
||
| 43 | $dryRun = $this->getOption( "dryrun", false); |
||
| 44 | $u = $this->getOption( 'u', false ); |
||
| 45 | |||
| 46 | $reportingInterval = 100; |
||
| 47 | $dbr = wfGetDB( DB_SLAVE ); |
||
| 48 | $ns_restrict = "page_namespace > -1"; |
||
| 49 | $tables = array('page'); |
||
| 50 | |||
| 51 | $seltables = array( 'page_id' ); |
||
| 52 | // Need to do for NS |
||
| 53 | if ( $ns > -1 ) { |
||
| 54 | if ( is_numeric( $ns ) ) { |
||
| 55 | $ns_restrict = "page_namespace = $ns"; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | // Default, no user |
||
| 60 | $user = null; |
||
| 61 | if ( $u ) { |
||
| 62 | // $user = User::newSystemUser("SDImport"); |
||
| 63 | $user = User::newFromName( $u ); |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | $res = $dbr->select( $tables, |
||
| 68 | $seltables, |
||
| 69 | array( |
||
| 70 | $ns_restrict ), |
||
| 71 | __METHOD__ |
||
| 72 | ); |
||
| 73 | $num = $dbr->numRows( $res ); |
||
| 74 | $this->output( "$num articles...\n" ); |
||
| 75 | $i = 0; |
||
| 76 | foreach ( $res as $row ) { |
||
| 77 | if ( !( ++$i % $reportingInterval ) ) { |
||
| 78 | $this->output( "$i\n" ); |
||
| 79 | wfWaitForSlaves(); // Doubt if necessary |
||
| 80 | } |
||
| 81 | if ( ! $dryRun ) { |
||
| 82 | self::refreshArticle( $row->page_id, $user ); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | } |
||
| 87 | |||
| 126 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: