Conditions | 13 |
Paths | 13 |
Total Lines | 15 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 182 |
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 |
||
18 | function iterable_column(iterable $iterable, $valueColumn, $keyColumn = null): \Generator |
||
19 | { |
||
20 | foreach ($iterable as $key => $value) { |
||
21 | if (is_array($value) || (is_object($value) && $value instanceof \ArrayAccess)) { |
||
22 | $key = isset($keyColumn) ? ($value[$keyColumn] ?? null) : $key; |
||
23 | $value = isset($valueColumn) ? ($value[$valueColumn] ?? null) : $value; |
||
24 | } elseif (is_object($value) && !$value instanceof \DateTimeInterface) { |
||
25 | $key = isset($keyColumn) ? ($value->$keyColumn ?? null) : $key; |
||
26 | $value = isset($valueColumn) ? ($value->$valueColumn ?? null) : $value; |
||
27 | } else { |
||
28 | $key = isset($keyColumn) ? null : $key; |
||
29 | $value = isset($valueColumn) ? null : $value; |
||
30 | } |
||
31 | |||
32 | yield $key => $value; |
||
33 | } |
||
35 |