DefaultsMutator::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.2
cc 4
eloc 9
nc 4
nop 2
crap 4
1
<?php
2
3
namespace Underscore\Mutator;
4
5
use Underscore\Collection;
6
use Underscore\Mutator;
7
8
class DefaultsMutator extends Mutator
9
{
10
    /**
11
     * Fill in null properties in object.
12
     *
13
     * Uses the first value present in any of the defaults.
14
     *
15
     * @param Collection $collection
16
     * @param mixed      $default
17
     * @param ...
18
     * @return Collection
19
     */
20 1
    public function __invoke($collection, $default)
0 ignored issues
show
Unused Code introduced by
The parameter $default is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22 1
        $defaults = func_get_args();
23 1
        array_shift($defaults); // remove $collection
24
25 1
        $collection = clone $collection;
26
27 1
        foreach ($defaults as $default) {
28 1
            foreach ($default as $key => $value) {
29 1
                if (!isset($collection[$key])) {
30 1
                    $collection[$key] = $value;
31
                }
32
            }
33
        }
34
35 1
        return $collection;
36
    }
37
}
38