ArrayMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 56
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getData() 0 10 2
A setParameters() 0 7 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dam
5
 * Date: 03/12/15
6
 * Time: 10:38
7
 */
8
9
namespace Mouf\Utils\DataSource\Mappers;
10
11
12
use Mouf\Utils\DataSource\Interfaces\DataSourceInterface;
13
use Mouf\Utils\DataSource\Interfaces\PickerInterface;
14
use Mouf\Utils\DataSource\Row;
15
16
class ArrayMapper implements DataSourceInterface
17
{
18
    /**
19
     * @var PickerInterface[]
20
     */
21
    private $matchers;
22
23
    /**
24
     * @var DataSourceInterface
25
     */
26
    private $dataSource;
27
28
    /**
29
     * @var array
30
     */
31
    private $params;
32
33
    /**
34
     * ArrayMapper constructor.
35
     * @Important
36
     * @param array<string,PickerInterface> $matchers
37
     * @param DataSourceInterface $dataSource
38
     * @param array $params
39
     */
40
    public function __construct(array $matchers, DataSourceInterface $dataSource, array $params = array())
41
    {
42
        $this->matchers = $matchers;
0 ignored issues
show
Documentation Bug introduced by
It seems like $matchers of type array<string,object<Mouf...faces\PickerInterface>> is incompatible with the declared type array<integer,object<Mou...faces\PickerInterface>> of property $matchers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $this->dataSource = $dataSource;
44
        $this->params = $params;
45
    }
46
47
    /**
48
     * @return array[]
49
     */
50
    public function getData()
51
    {
52
        $data = [];
53
        foreach ($this->dataSource->getData() as $row) {
54
            $data [] = array_map(function (PickerInterface $picker) use ($row) {
55
                return $picker->pick(new Row($row));
56
            }, $this->matchers);
57
        }
58
        return $data;
59
    }
60
61
    /**
62
     * @param array $params
63
     */
64
    public function setParameters(array $params)
65
    {
66
        if(empty($this->params)) {
67
            $this->params = $params;
68
        }
69
        $this->dataSource->setParameters($this->params);
70
    }
71
}