DefaultsMutator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 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