| Conditions | 11 |
| Paths | 9 |
| Total Lines | 64 |
| 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 |
||
| 19 | function run() { |
||
| 20 | wfProfileIn( __METHOD__ ); |
||
| 21 | |||
| 22 | if ( is_null( $this->title ) ) { |
||
| 23 | $this->error = "dtImport: Invalid title"; |
||
| 24 | wfProfileOut( __METHOD__ ); |
||
| 25 | return false; |
||
| 26 | } |
||
| 27 | |||
| 28 | if ( method_exists( 'WikiPage', 'getContent' ) ) { |
||
| 29 | $wikiPage = new WikiPage( $this->title ); |
||
| 30 | if ( !$wikiPage ) { |
||
| 31 | $this->error = 'dtImport: Wiki page not found "' . $this->title->getPrefixedDBkey() . '"'; |
||
| 32 | wfProfileOut( __METHOD__ ); |
||
| 33 | return false; |
||
| 34 | } |
||
| 35 | } else { |
||
| 36 | // Remove old support |
||
| 37 | return false; |
||
| 38 | } |
||
| 39 | $for_pages_that_exist = $this->params['for_pages_that_exist']; |
||
| 40 | if ( $for_pages_that_exist == 'skip' && $this->title->exists() ) { |
||
| 41 | return true; |
||
| 42 | } |
||
| 43 | |||
| 44 | // Change global $wgUser variable to the one specified by |
||
| 45 | // the job only for the extent of this import. |
||
| 46 | global $wgUser; |
||
| 47 | $actual_user = $wgUser; |
||
| 48 | $wgUser = User::newFromId( $this->params['user_id'] ); |
||
| 49 | $text = $this->params['text']; |
||
| 50 | $edit_summary = $this->params['edit_summary']; |
||
| 51 | |||
| 52 | // Act according to storage here |
||
| 53 | if ( $this->params['storage'] == "json" ) { |
||
| 54 | // TODO: to evaluate if check destination page here or before |
||
| 55 | |||
| 56 | // Handle JSON new content |
||
| 57 | $contentModel = $wikipage->getContentModel(); |
||
| 58 | if ( $contentModel === "json" || ! $wikipage->exists() ) { |
||
| 59 | $new_content = new JSONContent( $text ); |
||
| 60 | } |
||
| 61 | |||
| 62 | } else { |
||
| 63 | |||
| 64 | if ( $this->title->exists() ) { |
||
| 65 | if ( $for_pages_that_exist == 'append' ) { |
||
| 66 | // MW >= 1.21 |
||
| 67 | $existingText = $wikiPage->getContent()->getNativeData(); |
||
| 68 | $text = $existingText . "\n" . $text; |
||
| 69 | |||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | $new_content = new WikitextContent( $text ); |
||
| 74 | |||
| 75 | } |
||
| 76 | |||
| 77 | $wikiPage->doEditContent( $new_content, $edit_summary ); |
||
| 78 | |||
| 79 | $wgUser = $actual_user; |
||
| 80 | wfProfileOut( __METHOD__ ); |
||
| 81 | return true; |
||
| 82 | } |
||
| 83 | } |
||
| 84 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.