ObjectStorageTrait::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Shrikeh\Collection;
4
5
use Traversable;
6
use SplObjectStorage;
7
8
trait ObjectStorageTrait
9
{
10
    /**
11
     * Force that this trait is used inside an OuterIterator
12
     */
13
    use \Shrikeh\Collection\RequiresOuterIteratorTrait;
14
15
    public function __construct(Traversable $objects)
16
    {
17
        static::testOuterIterator($this);
18
        parent::__construct(new SplObjectStorage());
19
20
        foreach ($objects as $key => $value) {
21
            $this->append($value, $key);
22
        }
23
        $this->getStorage()->rewind();
24
    }
25
26
    /**
27
     * @return mixed
28
     */
29
    abstract protected function getStorage();
30
31
    /**
32
     * We don't want to make this abstract, because then we would defeat the
33
     * whole point of type hinting on this.
34
     * Usage within domain collections should be append(SomeDomainThing $thing, $key)
35
     * so instead we throw an Exception so a dev knows where the problem lies.
36
     */
37
    private function append($data, $key)
0 ignored issues
show
Unused Code introduced by
The parameter $data 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...
Unused Code introduced by
The parameter $key 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...
38
    {
39
        throw new \LogicException('you must override the append() method');
40
    }
41
}
42