GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( aae2bf...843868 )
by Baptiste
03:45 queued 01:33
created

ObjectStorage::merge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Innmind\Immutable;
4
5
use Innmind\Immutable\Exception\LogicException;
6
7
class ObjectStorage implements PrimitiveInterface, \Countable, \Iterator, \ArrayAccess, \Serializable
8
{
9
    private $objects;
10
11 16
    public function __construct(\SplObjectStorage $objects = null)
12
    {
13 16
        $this->objects = $objects ? clone $objects : new \SplObjectStorage;
14 16
        $this->objects->rewind();
15 16
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 4
    public function toPrimitive()
21
    {
22
        //so the inner SplObjectStorage object can't be modified
23 4
        return clone $this->objects;
24
    }
25
26
    /**
27
     * Merge storages
28
     *
29
     * @param self $storage
30
     *
31
     * @return self
32
     */
33 1
    public function merge(self $storage)
34
    {
35 1
        $objects = new \SplObjectStorage;
36 1
        $objects->addAll($this->objects);
37 1
        $objects->addAll($storage->objects);
38
39 1
        return new self($objects);
40
    }
41
42
    /**
43
     * Attach a new element to the storage
44
     *
45
     * @param object $object
46
     * @param mixed $data
47
     *
48
     * @return self
49
     */
50 13
    public function attach($object, $data = null)
51
    {
52 13
        $objects = clone $this->objects;
53 13
        $objects->attach($object, $data);
54
55 13
        return new self($objects);
56
    }
57
58
    /**
59
     * Check if the object is in this storage
60
     *
61
     * @param object $object
62
     *
63
     * @return bool
64
     */
65 4
    public function contains($object)
66
    {
67 4
        return $this->objects->contains($object);
68
    }
69
70
    /**
71
     * Remove the given object from the storage
72
     *
73
     * @param object $object
74
     *
75
     * @return self
76
     */
77 1
    public function detach($object)
78
    {
79 1
        $objects = clone $this->objects;
80 1
        $objects->detach($object);
81
82 1
        return new self($objects);
83
    }
84
85
    /**
86
     * Get the internal has for the given object
87
     *
88
     * @param object $object
89
     *
90
     * @return string
91
     */
92 1
    public function getHash($object)
93
    {
94 1
        return $this->objects->getHash($object);
95
    }
96
97
    /**
98
     * Return the info associated to the current object pointed by the internal pointer
99
     *
100
     * @return mixed
101
     */
102 1
    public function getInfo()
103
    {
104 1
        return $this->objects->getInfo();
105
    }
106
107
    /**
108
     * Remove all the elements contained in the given storage from the current one
109
     *
110
     * @param self $storage
111
     *
112
     * @return self
113
     */
114 1
    public function removeAll(self $storage)
115
    {
116 1
        $objects = clone $this->objects;
117 1
        $objects->removeAll($storage->objects);
118
119 1
        return new self($objects);
120
    }
121
122
    /**
123
     * Remove all elements not contained in the given storage
124
     *
125
     * @param self $storage
126
     *
127
     * @return self
128
     */
129 1
    public function removeAllExcept(self $storage)
130
    {
131 1
        $objects = clone $this->objects;
132 1
        $objects->removeAllExcept($storage->objects);
133
134 1
        return new self($objects);
135
    }
136
137
    /**
138
     * Associate data to the current object
139
     *
140
     * @param mixed $data
141
     *
142
     * @return self
143
     */
144 1
    public function setInfo($data)
145
    {
146 1
        $current = $this->objects->current();
147 1
        $objects = clone $this->objects;
148 1
        $objects[$current] = $data;
149
150 1
        return new self($objects);
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156 6
    public function count()
157
    {
158 6
        return $this->objects->count();
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164 1
    public function current()
165
    {
166 1
        return $this->objects->current();
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172 2
    public function next()
173
    {
174 2
        $this->objects->next();
175 2
    }
176
177
    /**
178
     * {@inheritdoc}
179
     */
180 1
    public function key()
181
    {
182 1
        return $this->objects->key();
183
    }
184
185
    /**
186
     * {@inheritdoc}
187
     */
188 1
    public function rewind()
189
    {
190 1
        $this->objects->rewind();
191 1
    }
192
193
    /**
194
     * {@inheritdoc}
195
     */
196 1
    public function valid()
197
    {
198 1
        return $this->objects->valid();
199
    }
200
201
    /**
202
     * {@inheritdoc}
203
     */
204 1
    public function offsetExists($object)
205
    {
206 1
        return $this->objects->offsetExists($object);
207
    }
208
209
    /**
210
     * {@inheritdoc}
211
     */
212 1
    public function offsetGet($object)
213
    {
214 1
        return $this->objects->offsetGet($object);
215
    }
216
217
    /**
218
     * {@inheritdoc}
219
     */
220 1
    public function offsetSet($object, $data = null)
221
    {
222 1
        throw new LogicException(
223
            'You can\'t modify an immutable object storage'
224 1
        );
225
    }
226
227
    /**
228
     * {@inheritdoc}
229
     */
230 1
    public function offsetUnset($object)
231
    {
232 1
        throw new LogicException(
233
            'You can\'t modify an immutable object storage'
234 1
        );
235
    }
236
237
    /**
238
     * {@inheritdoc}
239
     */
240 1
    public function serialize()
241
    {
242 1
        return $this->objects->serialize();
243
    }
244
245
    /**
246
     * {@inheritdoc}
247
     */
248 1
    public function unserialize($serialized)
249
    {
250 1
        $objects = clone $this->objects;
251 1
        $objects->unserialize($serialized);
252
253 1
        return new self($objects);
254
    }
255
}
256