Completed
Push — master ( 1e8f84...1fe24e )
by Ekin
03:27
created

Configuration::bind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
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
    /** @var array<string> */
20
    private array $specialRepositories = [];
21
22
    private Token $githubToken;
23
24 13
    public function __construct(Token $githubToken)
25
    {
26 13
        $this->githubToken = $githubToken;
27
    }
28
29 1
    public function setLogLevel(int $logLevel): self
30
    {
31 1
        $this->logLevel = $logLevel;
32
33 1
        return $this;
34
    }
35
36 2
    public function getLogLevel(): int
37
    {
38 2
        return $this->logLevel;
39
    }
40
41 9
    public function addWebsocketAddress(UriInterface $address): self
42
    {
43 9
        $this->websocketAddresses[] = $address;
44
45 9
        return $this;
46
    }
47
48 3
    public function websocketAddressExists(string $origin): bool
49
    {
50 3
        foreach ($this->websocketAddresses as $websocketAddress) {
51 3
            if ((string) $websocketAddress === $origin) {
52 2
                return true;
53
            }
54
        }
55
56 2
        return false;
57
    }
58
59 9
    public function bind(ServerAddress $address): self
60
    {
61 9
        $this->bind[] = $address;
62
63 9
        return $this;
64
    }
65
66
    /**
67
     * @return array<ServerAddress>
68
     */
69 2
    public function getServerAddresses(): array
70
    {
71 2
        return $this->bind;
72
    }
73
74
    public function addSpecialRepository(string $repository): self
75
    {
76
        $this->specialRepositories[] = $repository;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @return array<string>
83
     */
84 1
    public function getSpecialRepositories(): array
85
    {
86 1
        return $this->specialRepositories;
87
    }
88
89 2
    public function getGithubToken(): Token
90
    {
91 2
        return $this->githubToken;
92
    }
93
}
94