FlatMap   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
ccs 9
cts 9
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A flatMap() 0 14 3
1
<?php
2
3
namespace Cocur\Chain\Link;
4
5
/**
6
 * FlatMap.
7
 *
8
 * @author    Nicolas Reynis
9
 */
10
trait FlatMap
11
{
12
    /**
13
     * @param callable $callback
14
     *
15
     * @return self
16
     */
17 4
    public function flatMap(callable $callback): self
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