| Conditions | 16 |
| Paths | > 20000 |
| Total Lines | 114 |
| Code Lines | 69 |
| 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 |
||
| 52 | public function execute() { |
||
| 53 | $config = $this->getConfig(); |
||
| 54 | $feedClasses = $config->get( 'FeedClasses' ); |
||
| 55 | try { |
||
| 56 | $params = $this->extractRequestParams(); |
||
| 57 | |||
| 58 | if ( !$config->get( 'Feed' ) ) { |
||
| 59 | $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' ); |
||
| 60 | } |
||
| 61 | |||
| 62 | if ( !isset( $feedClasses[$params['feedformat']] ) ) { |
||
| 63 | $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' ); |
||
| 64 | } |
||
| 65 | |||
| 66 | // limit to the number of hours going from now back |
||
| 67 | $endTime = wfTimestamp( TS_MW, time() - intval( $params['hours'] * 60 * 60 ) ); |
||
| 68 | |||
| 69 | // Prepare parameters for nested request |
||
| 70 | $fauxReqArr = [ |
||
| 71 | 'action' => 'query', |
||
| 72 | 'meta' => 'siteinfo', |
||
| 73 | 'siprop' => 'general', |
||
| 74 | 'list' => 'watchlist', |
||
| 75 | 'wlprop' => 'title|user|comment|timestamp|ids', |
||
| 76 | 'wldir' => 'older', // reverse order - from newest to oldest |
||
| 77 | 'wlend' => $endTime, // stop at this time |
||
| 78 | 'wllimit' => min( 50, $this->getConfig()->get( 'FeedLimit' ) ) |
||
| 79 | ]; |
||
| 80 | |||
| 81 | if ( $params['wlowner'] !== null ) { |
||
| 82 | $fauxReqArr['wlowner'] = $params['wlowner']; |
||
| 83 | } |
||
| 84 | if ( $params['wltoken'] !== null ) { |
||
| 85 | $fauxReqArr['wltoken'] = $params['wltoken']; |
||
| 86 | } |
||
| 87 | if ( $params['wlexcludeuser'] !== null ) { |
||
| 88 | $fauxReqArr['wlexcludeuser'] = $params['wlexcludeuser']; |
||
| 89 | } |
||
| 90 | if ( $params['wlshow'] !== null ) { |
||
| 91 | $fauxReqArr['wlshow'] = $params['wlshow']; |
||
| 92 | } |
||
| 93 | if ( $params['wltype'] !== null ) { |
||
| 94 | $fauxReqArr['wltype'] = $params['wltype']; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Support linking directly to sections when possible |
||
| 98 | // (possible only if section name is present in comment) |
||
| 99 | if ( $params['linktosections'] ) { |
||
| 100 | $this->linkToSections = true; |
||
| 101 | } |
||
| 102 | |||
| 103 | // Check for 'allrev' parameter, and if found, show all revisions to each page on wl. |
||
| 104 | if ( $params['allrev'] ) { |
||
| 105 | $fauxReqArr['wlallrev'] = ''; |
||
| 106 | } |
||
| 107 | |||
| 108 | // Create the request |
||
| 109 | $fauxReq = new FauxRequest( $fauxReqArr ); |
||
| 110 | |||
| 111 | // Execute |
||
| 112 | $module = new ApiMain( $fauxReq ); |
||
| 113 | $module->execute(); |
||
| 114 | |||
| 115 | $data = $module->getResult()->getResultData( [ 'query', 'watchlist' ] ); |
||
| 116 | $feedItems = []; |
||
| 117 | foreach ( (array)$data as $key => $info ) { |
||
| 118 | if ( ApiResult::isMetadataKey( $key ) ) { |
||
| 119 | continue; |
||
| 120 | } |
||
| 121 | $feedItem = $this->createFeedItem( $info ); |
||
|
|
|||
| 122 | if ( $feedItem ) { |
||
| 123 | $feedItems[] = $feedItem; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | $msg = wfMessage( 'watchlist' )->inContentLanguage()->text(); |
||
| 128 | |||
| 129 | $feedTitle = $this->getConfig()->get( 'Sitename' ) . ' - ' . $msg . |
||
| 130 | ' [' . $this->getConfig()->get( 'LanguageCode' ) . ']'; |
||
| 131 | $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL(); |
||
| 132 | |||
| 133 | $feed = new $feedClasses[$params['feedformat']] ( |
||
| 134 | $feedTitle, |
||
| 135 | htmlspecialchars( $msg ), |
||
| 136 | $feedUrl |
||
| 137 | ); |
||
| 138 | |||
| 139 | ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); |
||
| 140 | } catch ( Exception $e ) { |
||
| 141 | // Error results should not be cached |
||
| 142 | $this->getMain()->setCacheMaxAge( 0 ); |
||
| 143 | |||
| 144 | // @todo FIXME: Localise brackets |
||
| 145 | $feedTitle = $this->getConfig()->get( 'Sitename' ) . ' - Error - ' . |
||
| 146 | wfMessage( 'watchlist' )->inContentLanguage()->text() . |
||
| 147 | ' [' . $this->getConfig()->get( 'LanguageCode' ) . ']'; |
||
| 148 | $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL(); |
||
| 149 | |||
| 150 | $feedFormat = isset( $params['feedformat'] ) ? $params['feedformat'] : 'rss'; |
||
| 151 | $msg = wfMessage( 'watchlist' )->inContentLanguage()->escaped(); |
||
| 152 | $feed = new $feedClasses[$feedFormat] ( $feedTitle, $msg, $feedUrl ); |
||
| 153 | |||
| 154 | if ( $e instanceof UsageException ) { |
||
| 155 | $errorCode = $e->getCodeString(); |
||
| 156 | } else { |
||
| 157 | // Something is seriously wrong |
||
| 158 | $errorCode = 'internal_api_error'; |
||
| 159 | } |
||
| 160 | |||
| 161 | $errorText = $e->getMessage(); |
||
| 162 | $feedItems[] = new FeedItem( "Error ($errorCode)", $errorText, '', '', '' ); |
||
| 163 | ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 301 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.