NginxConfigFile   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configContent() 0 4 1
A siteName() 0 6 1
A serverPort() 0 6 1
A protocol() 0 6 2
A shouldBeMonitoredByOhDear() 0 4 1
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