| Conditions | 10 |
| Paths | 11 |
| Total Lines | 25 |
| Code Lines | 14 |
| 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 |
||
| 48 | private function applyOrder(array $data, array $array): array |
||
| 49 | { |
||
| 50 | $result = []; |
||
| 51 | |||
| 52 | foreach ($array as $key => $value) { |
||
| 53 | if (is_string($key)) { |
||
| 54 | if (array_key_exists($key, $data)) { |
||
| 55 | $result[$key] = ArrayHelper::remove($data, $key); |
||
| 56 | } |
||
| 57 | } else { |
||
| 58 | foreach ($data as $dataKey => $dataValue) { |
||
| 59 | if (is_int($dataKey) && $dataValue === $value) { |
||
| 60 | $result[] = $dataValue; |
||
| 61 | unset($data[$dataKey]); |
||
| 62 | break; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($this->nested && is_array($value) && is_array($result[$key])) { |
||
| 68 | $result[$key] = $this->applyOrder($result[$key], $value); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | return array_merge($result, $data); |
||
| 73 | } |
||
| 75 |