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

HttpInputSource::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\InputSources;
5
6
class HttpInputSource implements InputSourceInterface
7
{
8
    /**
9
     * @var string[]
10
     */
11
    protected array $uris;
12
13
    protected ?string $username;
14
15
    /**
16
     * @var null|string|string[]
17
     */
18
    protected $password;
19
20
    /**
21
     * HttpInputSource constructor.
22
     *
23
     * @param string[]             $uris
24
     * @param string|null          $username
25
     * @param null|string|string[] $password
26
     */
27 4
    public function __construct(array $uris, ?string $username = null, $password = null)
28
    {
29 4
        $this->uris     = $uris;
30 4
        $this->username = $username;
31 4
        $this->password = $password;
32
    }
33
34
    /**
35
     * @return array<string,string|string[]>
36
     */
37 2
    public function toArray(): array
38
    {
39 2
        $response = [
40
            'type' => 'http',
41 2
            'uris' => $this->uris,
42
        ];
43
44 2
        if (!empty($this->username)) {
45 1
            $response['httpAuthenticationUsername'] = $this->username;
46
        }
47
48 2
        if (!empty($this->password)) {
49 1
            $response['httpAuthenticationPassword'] = $this->password;
50
        }
51
52 2
        return $response;
53
    }
54
}