Conditions | 9 |
Paths | 34 |
Total Lines | 58 |
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 |
||
118 | public function execute( $subPage ) { |
||
119 | parent::execute( $subPage ); |
||
120 | |||
121 | // Setup |
||
122 | $request = $this->getRequest(); |
||
123 | $parts = ( $subPage === '' ) ? [] : explode( '/', $subPage, 2 ); |
||
124 | $site = trim( $request->getVal( 'site', $parts[0] ?? '' ) ); |
||
125 | $page = trim( $request->getVal( 'page', $parts[1] ?? '' ) ); |
||
126 | |||
127 | $itemContent = null; |
||
|
|||
128 | |||
129 | // If there are enough data, then try to lookup the item content |
||
130 | if ( $site !== '' && $page !== '' ) { |
||
131 | // FIXME: This code is duplicated in ItemByTitleHelper::getItemId! |
||
132 | // Try to get a item content |
||
133 | $siteId = $this->stringNormalizer->trimToNFC( $site ); // no stripping of underscores here! |
||
134 | $pageName = $this->stringNormalizer->trimToNFC( $page ); |
||
135 | |||
136 | if ( !$this->sites->getSite( $siteId ) ) { |
||
137 | // HACK: If the site ID isn't known, add "wiki" to it; this allows the wikipedia |
||
138 | // subdomains to be used to refer to wikipedias, instead of requiring their |
||
139 | // full global id to be used. |
||
140 | // @todo: Ideally, if the site can't be looked up by global ID, we |
||
141 | // should try to look it up by local navigation ID. |
||
142 | // Support for this depends on bug T50934. |
||
143 | $siteId .= 'wiki'; |
||
144 | } |
||
145 | |||
146 | $itemId = $this->siteLinkLookup->getItemIdForLink( $siteId, $pageName ); |
||
147 | |||
148 | // Do we have an item content, and if not can we try harder? |
||
149 | if ( $itemId === null ) { |
||
150 | // Try harder by requesting normalization on the external site |
||
151 | $siteObj = $this->sites->getSite( $siteId ); |
||
152 | if ( $siteObj instanceof Site ) { |
||
153 | $pageName = $siteObj->normalizePageName( $page ); |
||
154 | if ( is_string( $pageName ) ) { // T191634 |
||
155 | $itemId = $this->siteLinkLookup->getItemIdForLink( $siteId, $pageName ); |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | |||
160 | // Redirect to the item page if we found its content |
||
161 | if ( $itemId !== null ) { |
||
162 | $title = $this->titleLookup->getTitleForId( $itemId ); |
||
163 | $query = $request->getValues(); |
||
164 | unset( $query['title'] ); |
||
165 | unset( $query['site'] ); |
||
166 | unset( $query['page'] ); |
||
167 | $itemUrl = $title->getFullURL( $query ); |
||
168 | $this->getOutput()->redirect( $itemUrl ); |
||
169 | return; |
||
170 | } |
||
171 | } |
||
172 | |||
173 | // If there is no item content post the switch form |
||
174 | $this->switchForm( $site, $page ); |
||
175 | } |
||
176 | |||
258 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.