Completed
Pull Request — master (#52)
by Pieter
06:43
created

Configuration::getGithubToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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
    public function __construct(Token $githubToken)
22
    {
23
        $this->githubToken = $githubToken;
24
    }
25
26
    public function setLogLevel(int $logLevel): self
27
    {
28
        $this->logLevel = $logLevel;
29
30
        return $this;
31
    }
32
33
    public function getLogLevel(): int
34
    {
35
        return $this->logLevel;
36
    }
37
38
    public function addWebsocketAddress(UriInterface $address): self
39
    {
40
        $this->websocketAddresses[] = $address;
41
42
        return $this;
43
    }
44
45
    public function websocketAddressExists(string $origin): bool
46
    {
47
        foreach ($this->websocketAddresses as $websocketAddress) {
48
            if ((string) $websocketAddress === $origin) {
49
                return true;
50
            }
51
        }
52
53
        return false;
54
    }
55
56
    public function bind(ServerAddress $address): self
57
    {
58
        $this->bind[] = $address;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @return array<ServerAddress>
65
     */
66
    public function getServerAddresses(): array
67
    {
68
        return $this->bind;
69
    }
70
71
    public function getGithubToken(): Token
72
    {
73
        return $this->githubToken;
74
    }
75
}
76