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

Configuration   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 65
ccs 22
cts 22
cp 1
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getServerAddresses() 0 3 1
A getGithubToken() 0 3 1
A getLogLevel() 0 3 1
A setLogLevel() 0 5 1
A addWebsocketAddress() 0 5 1
A websocketAddressExists() 0 9 3
A __construct() 0 3 1
A bind() 0 5 1
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