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

CloudInputSource::__construct()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
cc 4
nc 2
nop 3
crap 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\InputSources;
5
6
use InvalidArgumentException;
7
8
abstract class CloudInputSource implements InputSourceInterface
9
{
10
    /**
11
     * @var array<string>
12
     */
13
    protected array $uris;
14
15
    /**
16
     * @var array<string>
17
     */
18
    protected array $prefixes;
19
20
    /**
21
     * @var array<array<string,string>>
22
     */
23
    protected array $objects;
24
25
    /**
26
     * S3InputSource constructor.
27
     *
28
     * @param array<string>               $uris
29
     * @param array<string>               $prefixes
30
     * @param array<array<string,string>> $objects
31
     */
32 15
    public function __construct(array $uris = [], array $prefixes = [], array $objects = [])
33
    {
34 15
        $this->uris     = $uris;
35 15
        $this->prefixes = $prefixes;
36 15
        $this->objects  = $objects;
37
38 15
        if (count($uris) == 0 && count($prefixes) == 0 && count($objects) == 0) {
39 3
            throw new InvalidArgumentException('You have to specify either $uris, $prefixes or $objects');
40
        }
41
    }
42
43
    abstract protected function getCloudType(): string;
44
45
    /**
46
     * @return array<string,string|string[]|array<array<string,string>>>
47
     */
48 12
    public function toArray(): array
49
    {
50 12
        $response = [
51 12
            'type' => $this->getCloudType(),
52
        ];
53
54 12
        if (count($this->uris) > 0) {
55 6
            $response['uris'] = $this->uris;
56
        }
57
58 12
        if (count($this->prefixes) > 0) {
59 6
            $response['prefixes'] = $this->prefixes;
60
        }
61
62 12
        if (count($this->objects) > 0) {
63 6
            $response['objects'] = $this->objects;
64
        }
65
66 12
        return $response;
67
    }
68
}