| Conditions | 28 |
| Paths | 190 |
| Total Lines | 102 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 51 |
| CRAP Score | 35.8353 |
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 |
||
| 69 | 24 | public function replacement__callback($matches) |
|
| 70 | { |
||
| 71 | 24 | global $db_callback, $user_info, $db_prefix; |
|
| 72 | |||
| 73 | 24 | list ($values, $connection) = $db_callback; |
|
| 74 | |||
| 75 | // Connection gone??? This should *never* happen at this point, yet it does :'( |
||
| 76 | 24 | if (!$this->_validConnection($connection)) |
|
|
|
|||
| 77 | 24 | Errors::instance()->display_db_error(); |
|
| 78 | |||
| 79 | 24 | if ($matches[1] === 'db_prefix') |
|
| 80 | 24 | return $db_prefix; |
|
| 81 | |||
| 82 | 24 | if ($matches[1] === 'query_see_board') |
|
| 83 | 24 | return $user_info['query_see_board']; |
|
| 84 | |||
| 85 | 24 | if ($matches[1] === 'query_wanna_see_board') |
|
| 86 | 24 | return $user_info['query_wanna_see_board']; |
|
| 87 | |||
| 88 | 24 | if (!isset($matches[2])) |
|
| 89 | 24 | $this->error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 90 | |||
| 91 | 24 | if (!isset($values[$matches[2]])) |
|
| 92 | 24 | $this->error_backtrace('The database value you\'re trying to insert does not exist: ' . htmlspecialchars($matches[2], ENT_COMPAT, 'UTF-8'), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 93 | |||
| 94 | 24 | $replacement = $values[$matches[2]]; |
|
| 95 | |||
| 96 | 24 | switch ($matches[1]) |
|
| 97 | { |
||
| 98 | 24 | case 'int': |
|
| 99 | 15 | if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 100 | 15 | $this->error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 101 | 15 | return (string) (int) $replacement; |
|
| 102 | break; |
||
| 103 | |||
| 104 | 24 | case 'string': |
|
| 105 | 24 | case 'text': |
|
| 106 | 22 | return sprintf('\'%1$s\'', $this->escape_string($replacement)); |
|
| 107 | break; |
||
| 108 | |||
| 109 | 15 | case 'array_int': |
|
| 110 | 11 | if (is_array($replacement)) |
|
| 111 | 11 | { |
|
| 112 | 11 | if (empty($replacement)) |
|
| 113 | 11 | $this->error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 114 | |||
| 115 | 11 | foreach ($replacement as $key => $value) |
|
| 116 | { |
||
| 117 | 11 | if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 118 | 11 | $this->error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 119 | |||
| 120 | 11 | $replacement[$key] = (string) (int) $value; |
|
| 121 | 11 | } |
|
| 122 | |||
| 123 | 11 | return implode(', ', $replacement); |
|
| 124 | } |
||
| 125 | else |
||
| 126 | $this->error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
||
| 127 | |||
| 128 | break; |
||
| 129 | |||
| 130 | 14 | case 'array_string': |
|
| 131 | 10 | if (is_array($replacement)) |
|
| 132 | 10 | { |
|
| 133 | 10 | if (empty($replacement)) |
|
| 134 | 10 | $this->error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 135 | |||
| 136 | 10 | foreach ($replacement as $key => $value) |
|
| 137 | 10 | $replacement[$key] = sprintf('\'%1$s\'', $this->escape_string($value)); |
|
| 138 | |||
| 139 | 10 | return implode(', ', $replacement); |
|
| 140 | } |
||
| 141 | else |
||
| 142 | $this->error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
||
| 143 | break; |
||
| 144 | |||
| 145 | 13 | case 'date': |
|
| 146 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
||
| 147 | return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
||
| 148 | else |
||
| 149 | $this->error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
||
| 150 | break; |
||
| 151 | |||
| 152 | 13 | case 'float': |
|
| 153 | 1 | if (!is_numeric($replacement)) |
|
| 154 | 1 | $this->error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 155 | 1 | return (string) (float) $replacement; |
|
| 156 | break; |
||
| 157 | |||
| 158 | 12 | case 'identifier': |
|
| 159 | return '`' . strtr($replacement, array('`' => '', '.' => '')) . '`'; |
||
| 160 | break; |
||
| 161 | |||
| 162 | 12 | case 'raw': |
|
| 163 | 12 | return $replacement; |
|
| 164 | break; |
||
| 165 | |||
| 166 | default: |
||
| 167 | $this->error_backtrace('Undefined type used in the database query. (' . $matches[1] . ':' . $matches[2] . ')', '', false, __FILE__, __LINE__); |
||
| 168 | break; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 390 | } |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.