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

Circular   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getElement() 0 8 2
A __construct() 0 4 1
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
}