Merge::merge()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

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