Passed
Pull Request — master (#38)
by Teye
05:43
created

CombineInputSource::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 10
cc 3
nc 3
nop 1
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\InputSources;
5
6
use InvalidArgumentException;
7
8
class CombineInputSource implements InputSourceInterface
9
{
10
    /**
11
     * @var \Level23\Druid\InputSources\InputSourceInterface[]
12
     */
13
    protected array $inputSources;
14
15
    /**
16
     * @param array<\Level23\Druid\InputSources\InputSourceInterface> $inputSources
17
     */
18 2
    public function __construct(array $inputSources)
19
    {
20
        // Validate the input sources.
21 2
        foreach ($inputSources as $inputSource) {
22 2
            if (!$inputSource instanceof InputSourceInterface) {
23 1
                throw new InvalidArgumentException('Only input sources are allowed!');
24
            }
25
        }
26
27 1
        $this->inputSources = $inputSources;
28
    }
29
30
    /**
31
     * @return array<string,string|array<array<string,string|array<mixed>|bool|int>>>
32
     */
33 1
    public function toArray(): array
34
    {
35
        return [
36 1
            'type'      => 'combining',
37 1
            'delegates' => array_map(
38 1
                fn(InputSourceInterface $inputSource) => $inputSource->toArray(),
39 1
                $this->inputSources
40
            ),
41
        ];
42
    }
43
}