Row::next()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\View;
6
7
use Psi\Component\Grid\ColumnFactory;
8
use Psi\Component\Grid\GridContext;
9
use Psi\Component\Grid\Metadata\GridMetadata;
10
11
class Row implements \Iterator
12
{
13
    private $columnFactory;
14
    private $columnMetadatas;
15
    private $data;
16
17
    public function __construct(
18
        ColumnFactory $columnFactory,
19
        GridMetadata $gridMetadata,
20
        GridContext $gridContext,
21
        $data
22
    ) {
23
        $this->columnFactory = $columnFactory;
24
        $this->columnMetadatas = $gridMetadata->getColumnsForGroups($gridContext->getGroups());
25
        $this->data = $data;
26
    }
27
28
    public function getData()
29
    {
30
        return $this->data;
31
    }
32
33
    public function current(): Cell
34
    {
35
        $columnMetadata = current($this->columnMetadatas);
36
37
        return $this->columnFactory->createCell(
38
            $this->key(),
39
            $columnMetadata->getType(),
40
            $this->data,
41
            $columnMetadata->getOptions()
42
        );
43
    }
44
45
    public function next()
46
    {
47
        return next($this->columnMetadatas);
48
    }
49
50
    public function key()
51
    {
52
        return key($this->columnMetadatas);
53
    }
54
55
    public function rewind()
56
    {
57
        return reset($this->columnMetadatas);
58
    }
59
60
    public function valid()
61
    {
62
        return current($this->columnMetadatas) !== false;
63
    }
64
}
65