NginxConfigFile::siteName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace OhDear\ForgeSync;
4
5
class NginxConfigFile
6
{
7
    /** @var string */
8
    protected $configContent;
9
10
    public function __construct(string $configContent)
11
    {
12
        $this->configContent = $configContent;
13
    }
14
15
    public function configContent(): string
16
    {
17
        return $this->configContent;
18
    }
19
20
    public function siteName(): string
21
    {
22
        preg_match('/.?(server_name)\s([a-zA-Z._-]*).?/', $this->configContent, $matches);
23
24
        return last($matches);
25
    }
26
27
    public function serverPort(): ?string
28
    {
29
        preg_match("/.?(listen)\s([0-9a-zA-Z.]*).?/s", $this->configContent, $matches);
30
31
        return last($matches);
32
    }
33
34
    public function protocol(): string
35
    {
36
        return $this->serverPort() === '443'
37
            ? 'https'
38
            : 'http';
39
    }
40
41
    public function shouldBeMonitoredByOhDear(): bool
42
    {
43
        return ! str_contains($this->configContent, '#OH-DEAR-DO-NOT-MONITOR');
44
    }
45
}
46