| Conditions | 12 |
| Paths | 108 |
| Total Lines | 40 |
| Code Lines | 18 |
| 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 namespace XoopsModules\Protector; |
||
| 124 | public function checkSql($sql) |
||
| 125 | { |
||
| 126 | list($sql_wo_strings, $strings) = $this->separateStringsInSQL($sql); |
||
| 127 | |||
| 128 | // stage1: addslashes() processed or not |
||
| 129 | foreach ($this->doubtful_requests as $request) { |
||
| 130 | if (addslashes($request) != $request) { |
||
| 131 | if (false !== stripos($sql, trim($request))) { |
||
| 132 | // check the request stayed inside of strings as whole |
||
| 133 | $ok_flag = false; |
||
| 134 | foreach ($strings as $string) { |
||
| 135 | if (false !== strpos($string, $request)) { |
||
| 136 | $ok_flag = true; |
||
| 137 | break; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | if (!$ok_flag) { |
||
| 141 | $this->injectionFound($sql); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | // stage2: doubtful requests exists and outside of quotations ('or") |
||
| 148 | // $_GET['d'] = '1 UNION SELECT ...' |
||
| 149 | // NG: select a from b where c=$d |
||
| 150 | // OK: select a from b where c='$d_escaped' |
||
| 151 | // $_GET['d'] = '(select ... FROM)' |
||
| 152 | // NG: select a from b where c=(select ... from) |
||
| 153 | foreach ($this->doubtful_requests as $request) { |
||
| 154 | if (false !== strpos($sql_wo_strings, trim($request))) { |
||
| 155 | $this->injectionFound($sql); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | // stage3: comment exists or not without quoted strings (too sensitive?) |
||
| 160 | if (preg_match('/(\/\*|\-\-|\#)/', $sql_wo_strings, $regs)) { |
||
| 161 | foreach ($this->doubtful_requests as $request) { |
||
| 162 | if (false !== strpos($request, $regs[1])) { |
||
| 163 | $this->injectionFound($sql); |
||
| 164 | } |
||
| 196 |