Conditions | 11 |
Paths | 81 |
Total Lines | 61 |
Code Lines | 42 |
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 |
||
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 ((false !== $results) && @is_string($matches[0][0])) { |
||
67 | if ($matches[1][0] == $matches[2][0]) { |
||
68 | $file = str_replace(XOOPS_ROOT_PATH, '', $fileInfo->getPathname()); |
||
69 | $match = $matches[0][0]; |
||
70 | $output->outputIssue($output->makeOutputIssue($rule, $file, $match, $writable)); |
||
|
|||
71 | } |
||
72 | } |
||
73 | unset($matches); |
||
74 | |||
75 | // plugin function arguments must be quoted |
||
76 | $rule = 'noquotes'; |
||
77 | $pattern = $this->patterns[$rule]; |
||
78 | $results = preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER, 0); |
||
79 | if (false !== $results) { |
||
80 | @$match = $matches[0][0]; |
||
81 | if (!is_null($match) |
||
82 | && '<{if false}>' != $match // oddball case |
||
83 | ) { |
||
84 | $file = str_replace(XOOPS_ROOT_PATH, '', $fileInfo->getPathname()); |
||
85 | $output->outputIssue($output->makeOutputIssue($rule, $file, $match, $writable)); |
||
86 | } |
||
87 | } |
||
88 | unset($matches); |
||
89 | |||
90 | // includeq was removed, use include instead |
||
91 | $rule = 'includeq'; |
||
92 | $pattern = $this->patterns[$rule]; |
||
93 | $results = preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER, 0); |
||
94 | if (false !== $results) { |
||
95 | @$match = $matches[0][0]; |
||
96 | if (!is_null($match)) { |
||
97 | $file = str_replace(XOOPS_ROOT_PATH, '', $fileInfo->getPathname()); |
||
98 | $output->outputIssue($output->makeOutputIssue($rule, $file, $match, $writable)); |
||
99 | } |
||
100 | } |
||
101 | unset($matches); |
||
102 | |||
103 | // foreachq was removed, use foreach instead |
||
104 | $rule = 'foreachq'; |
||
105 | $pattern = $this->patterns[$rule]; |
||
106 | $results = preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER, 0); |
||
107 | if (false !== $results) { |
||
108 | @$match = $matches[0][0]; |
||
109 | if (!is_null($match)) { |
||
110 | $file = str_replace(XOOPS_ROOT_PATH, '', $fileInfo->getPathname()); |
||
111 | $output->outputIssue($output->makeOutputIssue($rule, $file, $match, $writable)); |
||
112 | } |
||
113 | } |
||
114 | unset($matches); |
||
115 | } |
||
117 |