Merge   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 23
ccs 6
cts 6
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A merge() 0 11 4
1
<?php
2
3
namespace Cocur\Chain\Link;
4
5
use Cocur\Chain\Chain;
6
7
/**
8
 * Merge.
9
 *
10
 * @author    Florian Eckerstorfer
11
 * @copyright 2015-2018 Florian Eckerstorfer
12
 */
13
trait Merge
14
{
15
    /**
16
     * Merge arrays.
17
     *
18
     * Merge the elements of one array with the elements of the array in the Chain.
19
     *
20
     * @param Chain|array $array   Array to merge with
21
     * @param array       $options options, including `recursive` to merge arrays recursive
22
     *
23
     * @return self
24
     */
25 4
    public function merge($array, array $options = []): self
26
    {
27 4
        $options = array_merge(['recursive' => false], $options);
28
29 4
        if ($options['recursive']) {
30 2
            $this->array = array_merge_recursive($this->array, $array instanceof Chain ? $array->array : $array);
31
        } else {
32 2
            $this->array = array_merge($this->array, $array instanceof Chain ? $array->array : $array);
33
        }
34
35 4
        return $this;
36
    }
37
}
38