| Conditions | 13 |
| Paths | 13 |
| Total Lines | 19 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| 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 /** @noinspection PhpVariableVariableInspection */ |
||
| 18 | 24 | function iterable_column(iterable $iterable, $valueColumn, $keyColumn = null): \Generator |
|
| 19 | { |
||
| 20 | 23 | foreach ($iterable as $key => $value) { |
|
| 21 | switch (true) { |
||
| 22 | 22 | case is_array($value) || (is_object($value) && $value instanceof \ArrayAccess): |
|
| 23 | 15 | $key = isset($keyColumn) ? ($value[$keyColumn] ?? null) : $key; |
|
| 24 | 15 | $value = isset($valueColumn) ? ($value[$valueColumn] ?? null) : $value; |
|
| 25 | 15 | break; |
|
| 26 | 15 | case is_object($value) && !$value instanceof \DateTimeInterface: |
|
| 27 | 15 | $key = isset($keyColumn) ? ($value->$keyColumn ?? null) : $key; |
|
| 28 | 15 | $value = isset($valueColumn) ? ($value->$valueColumn ?? null) : $value; |
|
| 29 | 15 | break; |
|
| 30 | default: |
||
| 31 | 1 | $key = isset($keyColumn) ? null : $key; |
|
| 32 | 1 | $value = isset($valueColumn) ? null : $value; |
|
| 33 | 1 | break; |
|
| 34 | } |
||
| 35 | |||
| 36 | 22 | yield $key => $value; |
|
| 37 | } |
||
| 39 |