| Conditions | 11 |
| Paths | 144 |
| Total Lines | 51 |
| Code Lines | 34 |
| 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 |
||
| 145 | public function renderOld(AbstractInline $inline, ElementRendererInterface $htmlRenderer) |
||
| 146 | { |
||
| 147 | $altContent = $inline->firstChild()->getContent(); |
||
| 148 | $attributes = [ |
||
| 149 | 'src' => strtr($inline->getUrl(), $this->getUrlTranslation()), |
||
| 150 | 'alt' => $altContent, |
||
| 151 | ]; |
||
| 152 | |||
| 153 | $caption = null; |
||
| 154 | |||
| 155 | $posJsonOpen = strpos($altContent, '{'); |
||
| 156 | $posJsonClose = strpos($altContent, '}'); |
||
| 157 | if ((false !== $posJsonOpen) and (false !== $posJsonClose)) { |
||
| 158 | $json = substr($altContent, $posJsonOpen, $posJsonClose); |
||
| 159 | $data = json_decode($json, true); |
||
| 160 | if (is_array($data)) { |
||
| 161 | if (isset($data['caption'])) { |
||
| 162 | $caption = $data['caption']; |
||
| 163 | unset($data['caption']); |
||
| 164 | } |
||
| 165 | $attributes = array_merge($attributes, $data); |
||
| 166 | } |
||
| 167 | $attributes['alt'] = substr($altContent, 0, $posJsonOpen); |
||
| 168 | } |
||
| 169 | |||
| 170 | if (isset($attributes['id'])) { |
||
| 171 | $imagesConfig = $this->getImagesConfig(); |
||
| 172 | $config = $imagesConfig[$attributes['id']]; |
||
| 173 | if (isset($config['width'])) { |
||
| 174 | $attributes['width'] = $config['width']; |
||
| 175 | } |
||
| 176 | if (isset($config['height'])) { |
||
| 177 | $attributes['height'] = $config['height']; |
||
| 178 | } |
||
| 179 | if (isset($config['caption'])) { |
||
| 180 | $caption = $config['caption']; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | if (!isset($attributes['layout'])) { |
||
| 185 | $attributes['layout'] = 'responsive'; |
||
| 186 | } |
||
| 187 | |||
| 188 | $figureContents = []; |
||
| 189 | $figure = new HtmlElement('figure'); |
||
| 190 | $figureContents[] = new HtmlElement('amp-img', $attributes); |
||
| 191 | if (null !== $caption) { |
||
| 192 | $figureContents[] = new HtmlElement('figcaption', [], $caption); |
||
| 193 | } |
||
| 194 | return new HtmlElement('figure', [], $figureContents); |
||
| 195 | } |
||
| 196 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.