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

CombineInputSource   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 11
c 0
b 0
f 0
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 7 1
A __construct() 0 10 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
}