Completed
Push — master ( 7f5313...51c1be )
by Ekin
03:37
created

Configuration::getServerAddresses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php declare(strict_types=1);
2
3
namespace ekinhbayar\GitAmp;
4
5
use ekinhbayar\GitAmp\Github\Token;
6
use League\Uri\Contracts\UriInterface;
7
use Monolog\Logger;
8
9
final class Configuration
10
{
11
    private int $logLevel = Logger::INFO;
12
13
    /** @var array<UriInterface> */
14
    private array $websocketAddresses = [];
15
16
    /** @var array<ServerAddress> */
17
    private array $bind = [];
18
19
    private Token $githubToken;
20
21 13
    public function __construct(Token $githubToken)
22
    {
23 13
        $this->githubToken = $githubToken;
24
    }
25
26 1
    public function setLogLevel(int $logLevel): self
27
    {
28 1
        $this->logLevel = $logLevel;
29
30 1
        return $this;
31
    }
32
33 2
    public function getLogLevel(): int
34
    {
35 2
        return $this->logLevel;
36
    }
37
38 9
    public function addWebsocketAddress(UriInterface $address): self
39
    {
40 9
        $this->websocketAddresses[] = $address;
41
42 9
        return $this;
43
    }
44
45 3
    public function websocketAddressExists(string $origin): bool
46
    {
47 3
        foreach ($this->websocketAddresses as $websocketAddress) {
48 3
            if ((string) $websocketAddress === $origin) {
49 2
                return true;
50
            }
51
        }
52
53 2
        return false;
54
    }
55
56 9
    public function bind(ServerAddress $address): self
57
    {
58 9
        $this->bind[] = $address;
59
60 9
        return $this;
61
    }
62
63
    /**
64
     * @return array<ServerAddress>
65
     */
66 2
    public function getServerAddresses(): array
67
    {
68 2
        return $this->bind;
69
    }
70
71 2
    public function getGithubToken(): Token
72
    {
73 2
        return $this->githubToken;
74
    }
75
}
76