| Conditions | 10 |
| Paths | 10 |
| Total Lines | 52 |
| Code Lines | 38 |
| Lines | 6 |
| Ratio | 11.54 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 48 | private function run( $resultPageSet = null ) { |
||
| 49 | $params = $this->extractRequestParams(); |
||
| 50 | $search = $params['search']; |
||
| 51 | $limit = $params['limit']; |
||
| 52 | $offset = $params['offset']; |
||
| 53 | |||
| 54 | $searchEngine = $this->buildSearchEngine( $params ); |
||
| 55 | $titles = $searchEngine->extractTitles( $searchEngine->completionSearchWithVariants( $search ) ); |
||
| 56 | |||
| 57 | if ( $resultPageSet ) { |
||
| 58 | View Code Duplication | $resultPageSet->setRedirectMergePolicy( function( array $current, array $new ) { |
|
| 59 | if ( !isset( $current['index'] ) || $new['index'] < $current['index'] ) { |
||
| 60 | $current['index'] = $new['index']; |
||
| 61 | } |
||
| 62 | return $current; |
||
| 63 | } ); |
||
| 64 | if ( count( $titles ) > $limit ) { |
||
| 65 | $this->setContinueEnumParameter( 'offset', $offset + $limit ); |
||
| 66 | array_pop( $titles ); |
||
| 67 | } |
||
| 68 | $resultPageSet->populateFromTitles( $titles ); |
||
| 69 | foreach ( $titles as $index => $title ) { |
||
| 70 | $resultPageSet->setGeneratorData( $title, [ 'index' => $index + $offset + 1 ] ); |
||
| 71 | } |
||
| 72 | } else { |
||
| 73 | $result = $this->getResult(); |
||
| 74 | $count = 0; |
||
| 75 | foreach ( $titles as $title ) { |
||
| 76 | if ( ++$count > $limit ) { |
||
| 77 | $this->setContinueEnumParameter( 'offset', $offset + $limit ); |
||
| 78 | break; |
||
| 79 | } |
||
| 80 | $vals = [ |
||
| 81 | 'ns' => intval( $title->getNamespace() ), |
||
| 82 | 'title' => $title->getPrefixedText(), |
||
| 83 | ]; |
||
| 84 | if ( $title->isSpecialPage() ) { |
||
| 85 | $vals['special'] = true; |
||
| 86 | } else { |
||
| 87 | $vals['pageid'] = intval( $title->getArticleID() ); |
||
| 88 | } |
||
| 89 | $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals ); |
||
| 90 | if ( !$fit ) { |
||
| 91 | $this->setContinueEnumParameter( 'offset', $offset + $count - 1 ); |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | $result->addIndexedTagName( |
||
| 96 | [ 'query', $this->getModuleName() ], $this->getModulePrefix() |
||
| 97 | ); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 158 |