| Conditions | 14 |
| Paths | 36 |
| Total Lines | 63 |
| Code Lines | 43 |
| 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 |
||
| 56 | public function inspectFile(SplFileInfo $fileInfo) |
||
| 57 | { |
||
| 58 | $output = $this->output; |
||
| 59 | $writable = $fileInfo->isWritable(); |
||
| 60 | $length = $fileInfo->getSize(); |
||
| 61 | $file = $fileInfo->openFile(); |
||
| 62 | $contents = $file->fread($length); |
||
| 63 | |||
| 64 | // variable names in Smarty 3 foreach item and from must be unique |
||
| 65 | $rule = 'varname'; |
||
| 66 | $pattern = $this->patterns[$rule]; |
||
| 67 | $results = preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER, 0); |
||
| 68 | if ((0 < (int)$results) && isset($matches[0][0]) && is_string($matches[0][0])) { |
||
| 69 | for ($i = 0; $i < (int)$results; $i++) { |
||
| 70 | if ($matches[1][$i] == $matches[2][$i]) { |
||
| 71 | $file = str_replace(XOOPS_ROOT_PATH, '', $fileInfo->getPathname()); |
||
| 72 | $match = $matches[0][$i]; |
||
| 73 | $output->outputIssue($output->makeOutputIssue($rule, $file, $match, $writable)); |
||
|
|
|||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | unset($matches); |
||
| 78 | |||
| 79 | // plugin function arguments must be quoted |
||
| 80 | $rule = 'noquotes'; |
||
| 81 | $pattern = $this->patterns[$rule]; |
||
| 82 | $results = preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER, 0); |
||
| 83 | if (0 < (int)$results) { |
||
| 84 | for ($i = 0; $i < (int)$results; $i++) { |
||
| 85 | $match = $matches[0][$i] ?? null; |
||
| 86 | if (null !== $match && '<{if false}>' !== $match) { // oddball case |
||
| 87 | $file = str_replace(XOOPS_ROOT_PATH, '', $fileInfo->getPathname()); |
||
| 88 | $output->outputIssue($output->makeOutputIssue($rule, $file, $match, $writable)); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 | unset($matches); |
||
| 93 | |||
| 94 | // includeq was removed, use include instead |
||
| 95 | $rule = 'includeq'; |
||
| 96 | $pattern = $this->patterns[$rule]; |
||
| 97 | $results = preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER, 0); |
||
| 98 | if (0 < (int)$results) { |
||
| 99 | $match = $matches[0][0] ?? null; |
||
| 100 | if (null !== $match) { |
||
| 101 | $file = str_replace(XOOPS_ROOT_PATH, '', $fileInfo->getPathname()); |
||
| 102 | $output->outputIssue($output->makeOutputIssue($rule, $file, $match, $writable)); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | unset($matches); |
||
| 106 | |||
| 107 | // foreachq was removed, use foreach instead |
||
| 108 | $rule = 'foreachq'; |
||
| 109 | $pattern = $this->patterns[$rule]; |
||
| 110 | $results = preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER, 0); |
||
| 111 | if (0 < (int)$results) { |
||
| 112 | $match = $matches[0][0] ?? null; |
||
| 113 | if (null !== $match) { |
||
| 114 | $file = str_replace(XOOPS_ROOT_PATH, '', $fileInfo->getPathname()); |
||
| 115 | $output->outputIssue($output->makeOutputIssue($rule, $file, $match, $writable)); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | unset($matches); |
||
| 119 | } |
||
| 121 |