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

FixedArrayStorageTrait::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 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