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