ObjectStorageTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
getStorage() 0 1 ?
A append() 0 4 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