Completed
Push — master ( 2d71cf...744a8a )
by Owen
01:19
created

MutableTrait::merge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Mundanity\Collection;
4
5
6
/**
7
 * Captures mutable methods applicable.
8
 *
9
 */
10
trait MutableTrait
11
{
12
    /**
13
     * {@inheritdoc}
14
     *
15
     */
16
    public function remove($item)
17
    {
18
        if ($key = array_search($item, $this->data, true)) {
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
            unset($this->data[$key]);
20
        }
21
        return $this;
22
    }
23
24
25
    /**
26
     * {@inheritdoc}
27
     *
28
     */
29
    public function filter(callable $callable)
30
    {
31
        $this->data = parent::filter($callable)
32
            ->toArray();
33
34
        return $this;
35
    }
36
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     */
42
    public function map(callable $callable)
43
    {
44
        $this->data = parent::map($callable)
45
            ->toArray();
46
47
        return $this;
48
    }
49
50
51
    /**
52
     * {@inheritdoc}
53
     *
54
     */
55
    public function diff(CollectionInterface ...$collection)
56
    {
57
        $this->data = parent::diff(...$collection)
58
            ->toArray();
59
60
        return $this;
61
    }
62
63
64
    /**
65
     * {@inheritdoc}
66
     *
67
     */
68
    public function intersect(CollectionInterface ...$collection)
69
    {
70
        $this->data = parent::intersect(...$collection)
71
            ->toArray();
72
73
        return $this;
74
    }
75
76
77
    /**
78
     * {@inheritdoc}
79
     *
80
     */
81
    public function merge(CollectionInterface ...$collection)
82
    {
83
        $this->data = parent::merge(...$collection)
84
            ->toArray();
85
86
        return $this;
87
    }
88
}
89