Conditions | 3 |
Paths | 3 |
Total Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
17 | 4 | public function flatMap(callable $callback) |
|
18 | { |
||
19 | 4 | $flattened = []; |
|
20 | 4 | foreach ($this->array as $index => $element) { |
|
|
|||
21 | 3 | $transformation = $callback($element, $index); |
|
22 | 3 | if (is_array($transformation)) { |
|
23 | 3 | array_push($flattened, ...$transformation); |
|
24 | } else { |
||
25 | 1 | $flattened[] = $transformation; |
|
26 | } |
||
27 | } |
||
28 | 4 | $this->array = $flattened; |
|
29 | |||
30 | 4 | return $this; |
|
31 | } |
||
32 | } |
||
33 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: