| Conditions | 10 | 
| Paths | 3 | 
| Total Lines | 31 | 
| 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 | ||
| 36 | public static function separateParameters($query, array $args) | ||
| 37 | 	{ | ||
| 38 | 		for ($i = 0; array_key_exists($i, $args) && array_key_exists($i + 1, $args) && ($arg = $args[$i]); $i++) { | ||
| 39 | 			if ( ! preg_match_all('~((\\:|\\?)(?P<name>[a-z0-9_]+))(?=(?:\\z|\\s|\\)))~i', $arg, $m)) { | ||
| 40 | continue; | ||
| 41 | } | ||
| 42 | |||
| 43 | $repeatedArgs = []; | ||
| 44 | 			foreach ($m['name'] as $l => $name) { | ||
| 45 | 				if (isset($repeatedArgs[$name])) { | ||
| 46 | continue; | ||
| 47 | } | ||
| 48 | |||
| 49 | $value = $args[++$i]; | ||
| 50 | $type = NULL; | ||
| 51 | |||
| 52 | 				if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) { | ||
| 53 | $type = Type::DATETIME; | ||
| 54 | |||
| 55 | 				} elseif (is_array($value)) { | ||
| 56 | $type = Connection::PARAM_STR_ARRAY; | ||
| 57 | } | ||
| 58 | |||
| 59 | $query->setParameter($name, $value, $type); | ||
| 60 | $repeatedArgs[$name] = TRUE; | ||
| 61 | unset($args[$i]); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | return $args; | ||
| 66 | } | ||
| 67 | |||
| 126 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.