FixedArrayStorageTrait::getStorage()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace Shrikeh\Collection;
4
5
use Traversable;
6
use SplFixedArray;
7
8
/**
9
 * Trait FixedArrayStorageTrait
10
 * @package Shrikeh\Collection
11
 */
12
trait FixedArrayStorageTrait
13
{
14
    /**
15
     * Enforce that this trait is applied to an OuterIterator
16
     */
17
    use \Shrikeh\Collection\RequiresOuterIteratorTrait;
18
19
    /**
20
     * FixedArrayStorageTrait constructor.
21
     * @param Traversable $objects
22
     */
23
    public function __construct(Traversable $objects)
24
    {
25
        /**
26
         * Test this is an outer iterator.
27
         */
28
        static::testOuterIterator($this);
29
        $arr = [];
30
        foreach ($objects as $key => $object) {
31
            $arr[$key] = $object;
32
        }
33
34
        parent::__construct(new SplFixedArray(count($arr)));
35
36
        foreach ($arr as $index => $obj) {
37
            $this->append($obj, $index);
38
        }
39
        $this->getStorage()->rewind();
40
    }
41
42
    /**
43
     * @param $data
44
     * @param $key
45
     */
46
    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...
47
    {
48
        $msg = 'you must override the %s method';
49
        throw new \LogicException(sprintf($msg, __FUNCTION__));
50
    }
51
52
    /**
53
     * @return mixed
54
     */
55
    abstract protected function getStorage();
56
}
57