| Conditions | 10 |
| Paths | 4 |
| Total Lines | 33 |
| 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 |
||
| 35 | public function startQuery($sql, array $params = null, array $types = null) |
||
| 36 | { |
||
| 37 | if (is_array($params)) { |
||
| 38 | foreach ($params as $index => $param) { |
||
| 39 | if (!is_string($params[$index])) { |
||
| 40 | continue; |
||
| 41 | } |
||
| 42 | |||
| 43 | // non utf-8 strings break json encoding |
||
| 44 | if (!preg_match('//u', $params[$index])) { |
||
| 45 | $params[$index] = self::BINARY_DATA_VALUE; |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | |||
| 49 | // detect if the too long string must be shorten |
||
| 50 | if (function_exists('mb_strlen')) { |
||
| 51 | if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) { |
||
| 52 | $params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]'; |
||
| 53 | continue; |
||
| 54 | } |
||
| 55 | } else { |
||
| 56 | if (self::MAX_STRING_LENGTH < strlen($params[$index])) { |
||
| 57 | $params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]'; |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | if (null !== $this->logger) { |
||
| 65 | $this->log($sql, null === $params ? array() : $params); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 87 |