Completed
Push — master ( 2f0a37...277b55 )
by Daniel
9s
created

Row::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid;
6
7
use Psi\Component\Grid\Metadata\GridMetadata;
8
use Psi\Component\View\ViewFactory;
9
use Psi\Component\View\ViewInterface;
10
11
class Row implements \Iterator
12
{
13
    private $viewFactory;
14
    private $columnMetadatas;
15
    private $data;
16
17
    public function __construct(
18
        ViewFactory $viewFactory,
19
        GridMetadata $gridMetadata,
20
        $data
21
    ) {
22
        $this->viewFactory = $viewFactory;
23
        $this->columnMetadatas = $gridMetadata->getColumns();
24
        $this->data = $data;
25
    }
26
27
    public function getData()
28
    {
29
        return $this->data;
30
    }
31
32
    public function current(): ViewInterface
33
    {
34
        $columnMetadata = current($this->columnMetadatas);
35
36
        return $this->viewFactory->create(
37
            $columnMetadata->getType(),
38
            $this->data,
39
            array_merge([
40
                'column_name' => $this->key(),
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