ProviderArray::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Eclipxe\XlsxExporter\Providers;
6
7
use Eclipxe\XlsxExporter\ProviderInterface;
8
use Eclipxe\XlsxExporter\Utils\ProviderGetValue;
9
10
class ProviderArray implements ProviderInterface
11
{
12
    /** @var array<int, array<scalar|null>> */
13
    private array $dataset;
14
15
    private int $index;
16
17
    private int $count;
18
19
    /** @param array<array<scalar|null>> $dataset */
20 3
    public function __construct(array $dataset)
21
    {
22 3
        $this->dataset = array_values($dataset);
23 3
        $this->count = count($this->dataset);
24 3
        $this->index = 0;
25
    }
26
27 3
    public function get(string $key)
28
    {
29 3
        if (! $this->valid()) {
30 2
            return null;
31
        }
32 3
        return ProviderGetValue::get($this->dataset[$this->index], $key);
33
    }
34
35 3
    public function next(): void
36
    {
37 3
        $this->index = $this->index + 1;
38
    }
39
40 3
    public function valid(): bool
41
    {
42 3
        return ($this->index < $this->count);
43
    }
44
45 1
    public function count(): int
46
    {
47 1
        return $this->count;
48
    }
49
}
50