| Conditions | 11 |
| Paths | 8 |
| Total Lines | 42 |
| 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 |
||
| 146 | private function newItem( array /* of SMWResultArray */ $row ) { |
||
| 147 | |||
| 148 | $item = new Item(); |
||
| 149 | $item->setFormatterCallback( [ $this, 'getFormattedList' ] ); |
||
| 150 | |||
| 151 | foreach ( $row as /* SMWResultArray */ $field ) { |
||
| 152 | $printRequest = $field->getPrintRequest(); |
||
| 153 | $values = []; |
||
| 154 | |||
| 155 | $label = strtolower( $printRequest->getLabel() ); |
||
| 156 | $dataValue = $field->getNextDataValue(); |
||
| 157 | |||
| 158 | if ( $dataValue === false ) { |
||
| 159 | continue; |
||
| 160 | } |
||
| 161 | |||
| 162 | if ( $label === 'date' && $dataValue instanceof TimeValue ) { |
||
| 163 | $item->set( 'year', $dataValue->getYear() ); |
||
| 164 | $item->set( 'month', $dataValue->getMonth() ); |
||
| 165 | } elseif ( $label === 'author' || $label === 'authors' ) { |
||
| 166 | $values[] = $dataValue->getShortWikiText(); |
||
| 167 | |||
| 168 | while ( ( /* SMWDataValue */ $dataValue = $field->getNextDataValue() ) !== false ) { |
||
| 169 | $values[] = $dataValue->getShortWikiText(); |
||
| 170 | } |
||
| 171 | |||
| 172 | $item->set( 'author', $values ); |
||
| 173 | } elseif ( $label === 'editor' || $label === 'editors' ) { |
||
| 174 | $values[] = $dataValue->getShortWikiText(); |
||
| 175 | |||
| 176 | while ( ( /* SMWDataValue */ $dataValue = $field->getNextDataValue() ) !== false ) { |
||
| 177 | $values[] = $dataValue->getShortWikiText(); |
||
| 178 | } |
||
| 179 | |||
| 180 | $item->set( 'editor', $values ); |
||
| 181 | } else { |
||
| 182 | $item->set( $label, $dataValue->getShortWikiText() ); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | return $item; |
||
| 187 | } |
||
| 188 | |||
| 190 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.