| Conditions | 11 |
| Paths | 5 |
| Total Lines | 47 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 50 | function prefilter(string $c) |
||
| 51 | { |
||
| 52 | global $syntaxHighlighter; |
||
| 53 | $dom = new SmartDOMDocument('1.0', 'ISO-8859-15'); |
||
| 54 | $dom->preserveWhiteSpace = true; |
||
| 55 | $dom->formatOutput = false; |
||
| 56 | |||
| 57 | if (!$dom->loadHTML($c)) { |
||
| 58 | \HTML\js::var('HTML_ERROR', json_encode(['error' => true, 'message' => 'HTML Optimizer failed'])); |
||
| 59 | echo $c; |
||
| 60 | |||
| 61 | return; |
||
| 62 | } |
||
| 63 | |||
| 64 | $xpath = new SmartDOMXpath($dom); |
||
| 65 | |||
| 66 | $title = getTitle($dom); |
||
| 67 | $pres = $xpath->query('//pre'); |
||
|
|
|||
| 68 | if (!empty($pres)) { |
||
| 69 | foreach ($pres as $pre) { |
||
| 70 | if (is_json($pre->innerHTML)) { |
||
| 71 | $pre->innerHTML = \JSON\json::beautify(json_decode($pre->innerHTML)); |
||
| 72 | if (!$syntaxHighlighter) { |
||
| 73 | $syntaxHighlighter = true; |
||
| 74 | insertBodyFirst($xpath, createScript($dom, ['src' => '/assets/highlight.js/loader.js', 'cache' => 'true'])); |
||
| 75 | } |
||
| 76 | if (empty(trim($pre->getAttribute('class')))) { |
||
| 77 | $pre->setAttribute('class', 'json'); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | if (empty(trim($pre->getAttribute('title')))) { |
||
| 81 | $pre->setAttribute('title', $title); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | $textareas = $xpath->query('//textarea'); |
||
| 87 | if (!empty($textareas)) { |
||
| 88 | foreach ($textareas as $area) { |
||
| 89 | if ($area->hasAttribute('innerhtml')) { |
||
| 90 | $area->innerHTML = base64_decode($area->getAttribute('innerhtml')); |
||
| 91 | $area->removeAttribute('innerhtml'); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | return $dom->saveHTML(); |
||
| 97 | } |
||
| 98 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.