Completed
Push — master ( a30a66...9886a6 )
by Alec
06:30
created

Circular::getElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 01.11.18
5
 * Time: 16:10
6
 */
7
declare(strict_types=1);
8
9
namespace AlecRabbit;
10
11
12
class Circular
13
{
14
    /** @var array */
15
    protected $data;
16
17
    /**
18
     * Circular constructor.
19
     * @param array $data
20
     */
21
    public function __construct(array $data)
22
    {
23
        $this->data = $data;
24
        reset($this->data);
25
    }
26
27
    /**
28
     * @return mixed
29
     */
30
    public function getElement()
31
    {
32
        if (($result = current($this->data)) === false) {
33
            $result = reset($this->data);
34
        }
35
        next($this->data);
36
37
        return $result;
38
    }
39
40
41
}