FlattenMutator::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
crap 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