FlattenMutator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
c 4
b 0
f 0
lcom 0
cbo 1
dl 0
loc 19
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 3
1
<?php
2
3
namespace Underscore\Mutator;
4
5
use Underscore\Collection;
6
use Underscore\Mutator;
7
8
class FlattenMutator extends Mutator
9
{
10
    /**
11
     * Performs shallow flatten operation on collection (unwraps first level of array)
12
     *
13
     * @param Collection $collection
14
     * @return Collection
15
     */
16 3
    public function __invoke($collection)
17
    {
18 3
        $newCollection = [];
19
20 3
        foreach ($collection as $value) {
21 2
            $newCollection = array_merge($newCollection, is_array($value) ? $value : [$value]);
22
        }
23
24 3
        return $this->copyCollectionWith($collection, $newCollection);
25
    }
26
}
27