RowBuilder::setParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dam
5
 * Date: 04/12/15
6
 * Time: 15:19
7
 */
8
9
namespace Mouf\Utils\DataSource;
10
11
12
use Mouf\Utils\DataSource\Interfaces\DataSourceInterface;
13
use Mouf\Utils\DataSource\Interfaces\ParameterizableInterface;
14
use Mouf\Utils\DataSource\Interfaces\RowInterface;
15
16
class RowBuilder implements RowInterface
17
{
18
    /**
19
     * @var RowInterface[]
20
     */
21
    private $mergedRows;
22
23
    /**
24
     * @var array<string, DataSourceInterface>
25
     */
26
    private $datasourceAttributes;
27
28
    /**
29
     * @var array<string, RowInterface>
30
     */
31
    private $rowAttributes;
32
33
    /**
34
     * @var array
35
     */
36
    private $params;
37
38
    /**
39
     * RowBuilder constructor.
40
     * @Important
41
     * @param RowInterface[] $mergedRows
42
     * @param array<string,DataSourceInterface> $datasourceAttributes
43
     * @param array<string, RowInterface> $rowAttributes
44
     * @param array $params
45
     */
46
    public function __construct(array $mergedRows = array(), array $datasourceAttributes = array(),
47
                                array $rowAttributes = array(), array $params = array())
48
    {
49
        $this->mergedRows = $mergedRows;
50
        $this->datasourceAttributes = $datasourceAttributes;
51
        $this->rowAttributes = $rowAttributes;
52
        $this->params = $params;
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function getRow()
59
    {
60
        $row = [];
61
        foreach($this->mergedRows as $mergeRow) {
62
            $mergeRow->setParameters($this->params);
63
            if($currentRow = $mergeRow->getRow()) {
64
                $row += $currentRow;
65
            }
66
        }
67
68
        foreach($this->datasourceAttributes as $key => $dataSourceAttribute) {
69
            /* @var $dataSourceAttribute DataSourceInterface */
70
            $dataSourceAttribute->setParameters($this->params);
71
            if($currentData = $dataSourceAttribute->getData()) {
72
                $row[$key] = $currentData;
73
            }
74
        }
75
76
        foreach($this->rowAttributes as $key => $rowAttribute) {
77
            /* @var $rowAttribute RowInterface */
78
            $rowAttribute->setParameters($this->params);
79
            if($currentRow = $rowAttribute->getRow()) {
80
                $row[$key] = $currentRow;
81
            }
82
        }
83
84
        return $row;
85
    }
86
87
    /**
88
     * @param array $params
89
     */
90
    public function setParameters(array $params)
91
    {
92
        $this->params = $params;
93
    }
94
}