Completed
Push — master ( bc8348...7e1aef )
by Barney
02:46
created

FixedArrayStorageTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A append() 0 5 1
getStorage() 0 1 ?
1
<?php
2
3
namespace Shrikeh\Collection;
4
5
use Traversable;
6
use SplFixedArray;
7
8
trait FixedArrayStorageTrait
9
{
10
    use \Shrikeh\Collection\RequiresOuterIteratorTrait;
11
12
    public function __construct(Traversable $objects)
13
    {
14
        static::testOuterIterator($this);
15
        $arr = [];
16
        foreach ($objects as $object) {
17
            $arr[] = $object;
18
        }
19
        parent::__construct(new SplFixedArray(count($arr)));
20
21
        foreach ($arr as $index => $obj) {
22
            $this->append($obj, $index);
23
        }
24
        $this->getStorage()->rewind();
25
    }
26
27
    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...
28
    {
29
        $msg = 'you must override the %s method';
30
        throw new \LogicException(sprintf($msg, __FUNCTION__));
31
    }
32
33
    abstract protected function getStorage();
34
}
35