| Conditions | 14 |
| Paths | 27 |
| Total Lines | 51 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 27 |
| CRAP Score | 15.7109 |
| 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 AgelxNash\Modx\Evo\Database\Traits; |
||
| 105 | 1 | public function prepareValues($data, $level = 1, $skipFieldNames = false) |
|
| 106 | { |
||
| 107 | 1 | $fields = []; |
|
| 108 | 1 | $values = []; |
|
| 109 | 1 | $maxLevel = $level; |
|
| 110 | 1 | $wrap = false; |
|
| 111 | |||
| 112 | 1 | if (\is_array($data)) { |
|
| 113 | 1 | foreach ($data as $key => $value) { |
|
| 114 | 1 | if (\is_array($value)) { |
|
| 115 | 1 | if ($level > 2) { |
|
| 116 | throw new Exceptions\TooManyLoopsException(); |
||
| 117 | } |
||
| 118 | 1 | $maxLevel++; |
|
| 119 | 1 | $out = $this->prepareValues($value, $level + 1); |
|
| 120 | 1 | if (empty($fields)) { |
|
| 121 | 1 | $fields = $out['fields']; |
|
| 122 | 1 | } elseif ($fields !== $out['fields'] && $skipFieldNames === false) { |
|
| 123 | throw (new Exceptions\InvaludFieldException("Don't match field names")) |
||
| 124 | ->setData($data); |
||
| 125 | } |
||
| 126 | 1 | $wrap = true; |
|
| 127 | 1 | $values[] = $out['values']; |
|
| 128 | } else { |
||
| 129 | 1 | $fields[] = $key; |
|
| 130 | 1 | $values[] = $this->prepareNull($value); |
|
| 131 | } |
||
| 132 | } |
||
| 133 | 1 | if (\is_array($values)) { |
|
| 134 | 1 | $values = implode(', ', $values); |
|
| 135 | } |
||
| 136 | 1 | if ($wrap === false) { |
|
| 137 | 1 | $values = '(' . $values . ')'; |
|
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | 1 | if (! \is_scalar($values)) { |
|
| 142 | throw (new Exceptions\InvaludFieldException('values')) |
||
| 143 | ->setData($values); |
||
| 144 | } |
||
| 145 | |||
| 146 | 1 | if (($fields = $this->checkFields($fields, $maxLevel, $skipFieldNames))=== false) { |
|
| 147 | throw (new Exceptions\InvaludFieldException('fields name')) |
||
| 148 | ->setData($data); |
||
| 149 | } |
||
| 150 | |||
| 151 | 1 | if ($level === 2) { |
|
| 152 | 1 | return compact('fields', 'values'); |
|
| 153 | } |
||
| 154 | |||
| 155 | 1 | return (empty($fields) ? '' : $fields . ' VALUES ') . $values; |
|
|
1 ignored issue
–
show
|
|||
| 156 | } |
||
| 272 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.