| Conditions | 13 |
| Paths | 17 |
| Total Lines | 45 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 13 |
| 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 |
||
| 39 | protected function generateQuery($params): string |
||
| 40 | { |
||
| 41 | 41 | if (!is_array($params)) |
|
| 42 | { |
||
| 43 | 41 | return ''; |
|
| 44 | 41 | } |
|
| 45 | |||
| 46 | 33 | $args = []; |
|
| 47 | foreach ($params as $k => $v) |
||
| 48 | 8 | { |
|
| 49 | if (is_int($k)) |
||
| 50 | 2 | { |
|
| 51 | if ($v === '') |
||
| 52 | 6 | { |
|
| 53 | continue; |
||
| 54 | } |
||
| 55 | |||
| 56 | 33 | $args[$k] = $v; |
|
| 57 | continue; |
||
| 58 | } |
||
| 59 | |||
| 60 | 41 | // A substitution token like $1 $2{stuff}, should be left alone |
|
| 61 | if (is_string($v) && $v !== '') |
||
| 62 | { |
||
| 63 | // A sprintf token (%1$d %2$s etc.) should be left alone, as should |
||
| 64 | // a substitution token like $1 $2{stuff} |
||
| 65 | if (($v[0] === '$' && preg_match('~^\$\d({.*})?$~m', $v) !== 0) |
||
| 66 | || ($v[0] === '%' && preg_match('~^%\d\$[ds]$~m', $v) !== 0)) |
||
| 67 | { |
||
| 68 | $args[$k] = $k . '=' . $v; |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($v === null) |
||
| 74 | { |
||
| 75 | continue; |
||
| 76 | } |
||
| 77 | |||
| 78 | $args[$k] = $k . '=' . urlencode($v); |
||
| 79 | } |
||
| 80 | |||
| 81 | $args = $this->getHash($args); |
||
| 82 | |||
| 83 | return (!empty($args) ? $this->_separator : '') . implode($this->_separator, $args); |
||
| 84 | } |
||
| 86 |