Conditions | 3 |
Paths | 3 |
Total Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
17 | public function flatMap(callable $callback) |
||
18 | { |
||
19 | $flattened = []; |
||
20 | foreach ($this->array as $index => $element) { |
||
|
|||
21 | $transformation = $callback($element, $index); |
||
22 | if (is_array($transformation)) { |
||
23 | array_push($flattened, ...$transformation); |
||
24 | } else { |
||
25 | $flattened[] = $transformation; |
||
26 | } |
||
27 | } |
||
28 | $this->array = $flattened; |
||
29 | |||
30 | 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: