Completed
Pull Request — master (#10)
by Tomáš
03:17
created

CompositeDataSource::refresh()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is a part of Sculpin.
5
 *
6
 * (c) Dragonfly Development Inc.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Symplify\PHP7_Sculpin\Source;
13
14
final class CompositeDataSource implements DataSourceInterface
15
{
16
    /**
17
     * Data sources.
18
     *
19
     * @var array
20
     */
21
    private $dataSources = [];
22
23
    /**
24
     * Constructor.
25
     *
26
     * @param array $dataSources Data sources
27
     */
28 3
    public function __construct(array $dataSources = [])
29
    {
30 3
        foreach ($dataSources as $dataSource) {
31 3
            $this->dataSources[$dataSource->dataSourceId()] = $dataSource;
32
        }
33 3
    }
34
35
    /**
36
     * Add a Data Source.
37
     *
38
     * @param DataSourceInterface $dataSource Data Source
39
     */
40 1
    public function addDataSource(DataSourceInterface $dataSource)
41
    {
42 1
        $this->dataSources[$dataSource->dataSourceId()] = $dataSource;
43 1
    }
44
45
    /**
46
     * Backing Data Sources.
47
     *
48
     * @return array
49
     */
50 1
    public function dataSources()
51
    {
52 1
        return $this->dataSources;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function dataSourceId()
59
    {
60 1
        return 'CompositeDataSource('.implode(',', array_map(function ($dataSource) {
61 1
            return $dataSource->dataSourceId();
62 1
        }, $this->dataSources));
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 1
    public function refresh(SourceSet $sourceSet)
69
    {
70 1
        foreach ($this->dataSources as $dataSource) {
71 1
            $dataSource->refresh($sourceSet);
72
        }
73 1
    }
74
}
75