| Total Complexity | 8 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 80% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class Circular |
||
| 8 | { |
||
| 9 | /** @var mixed */ |
||
| 10 | protected $data; |
||
| 11 | |||
| 12 | /** @var bool */ |
||
| 13 | protected $oneElement = false; |
||
| 14 | |||
| 15 | /** @var int */ |
||
| 16 | protected $idx = -1; // To pass tests written before |
||
| 17 | |||
| 18 | /** @var int */ |
||
| 19 | protected $length = 0; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Circular constructor. |
||
| 23 | * @param array $data |
||
| 24 | */ |
||
| 25 | 28 | public function __construct(array $data) |
|
| 28 | 28 | } |
|
| 29 | |||
| 30 | /** |
||
| 31 | * @param array $data |
||
| 32 | * @return mixed |
||
| 33 | */ |
||
| 34 | 28 | protected function refineData(array $data) |
|
| 35 | { |
||
| 36 | 28 | $this->length = count($data); |
|
| 37 | 28 | if (1 === $this->length) { |
|
| 38 | 28 | $this->oneElement = true; |
|
| 39 | 28 | return reset($data); |
|
| 40 | } |
||
| 41 | 21 | if (0 === $this->length) { |
|
| 42 | $this->oneElement = true; |
||
| 43 | return null; |
||
| 44 | } |
||
| 45 | 21 | return $data; |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return mixed |
||
| 50 | */ |
||
| 51 | public function __invoke() |
||
| 52 | { |
||
| 53 | return $this->value(); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return mixed |
||
| 58 | */ |
||
| 59 | 25 | public function value() |
|
| 68 | } |
||
| 69 | } |
||
| 70 |