Completed
Push — master ( 406296...0a0b96 )
by Daniel
07:00 queued 04:29
created

Row   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 53
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getData() 0 4 1
A current() 0 11 1
A next() 0 4 1
A key() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\View;
6
7
use Psi\Component\Grid\CellFactory;
8
use Psi\Component\Grid\CellViewInterface;
9
use Psi\Component\Grid\Metadata\GridMetadata;
10
use Psi\Component\Grid\RowData;
11
12
class Row implements \Iterator
13
{
14
    private $cellFactory;
15
    private $columnMetadatas;
16
    private $data;
17
18
    public function __construct(
19
        CellFactory $cellFactory,
20
        GridMetadata $gridMetadata,
21
        $data
22
    ) {
23
        $this->cellFactory = $cellFactory;
24
        $this->columnMetadatas = $gridMetadata->getColumns();
25
        $this->data = $data;
26
    }
27
28
    public function getData()
29
    {
30
        return $this->data;
31
    }
32
33
    public function current(): CellViewInterface
34
    {
35
        $columnMetadata = current($this->columnMetadatas);
36
37
        return $this->cellFactory->create(
38
            $this->key(),
39
            $columnMetadata->getType(),
40
            RowData::fromObject($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