SeekableTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A seek() 0 14 3
1
<?php
2
/**
3
 * File SeekableTrait.php
4
 *
5
 * @author Edward Pfremmer <[email protected]>
6
 */
7
namespace Epfremme\Collection\Traits;
8
9
/**
10
 * Trait SeekableTrait
11
 *
12
 * @property array|mixed[] $elements
13
 * @package Epfremme\Collection\Traits
14
 * @uses \SeekableIterator
15
 */
16
trait SeekableTrait
17
{
18
    /**
19
     * Seek to a position within the collection
20
     *
21
     * @param $position
22
     * @return void
23
     */
24 5
    public function seek($position)
25
    {
26 5
        if (!array_key_exists($position, $this->elements)) {
27 1
            throw new \InvalidArgumentException(
28 1
                sprintf('Position %s does not exist in collection', $position)
29 1
            );
30
        }
31
32 4
        reset($this->elements);
33
34 4
        while (key($this->elements) !== $position) {
35 4
            next($this->elements);
36 4
        }
37 4
    }
38
}
39