GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( da7651...84ea09 )
by Leandro
03:32
created

Domain::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * Domain file
4
 *
5
 * @author     Leandro Silva <[email protected]>
6
 * @category   LosDomain
7
 * @license    https://github.com/Lansoweb/LosDomain/blob/master/LICENSE MIT License
8
 * @link       http://github.com/LansoWeb/LosDomain
9
 */
10
namespace LosDomain;
11
12
/**
13
 * Domain class
14
 *
15
 * @author     Leandro Silva <[email protected]>
16
 * @category   LosDomain
17
 * @license    https://github.com/Lansoweb/LosDomain/blob/master/LICENSE MIT License
18
 * @link       http://github.com/LansoWeb/LosDomain
19
 */
20
final class Domain
21
{
22
    const DEFAULT_DOMAIN = 'default';
23
24
    private $domain;
25
26
    /**
27
     * Domain constructor.
28
     * @param $domain
29
     */
30
    public function __construct(string $domain = null)
31
    {
32
        if ($domain === null) {
33
            $domain = $this->detectDomain();
34
        }
35
        $this->domain = $domain;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function domain() : string
42
    {
43
        return $this->domain;
44
    }
45
46
    public function toString() : string
47
    {
48
        return $this->domain;
49
    }
50
51
    public function __toString() : string
52
    {
53
        return $this->toString();
54
    }
55
56
    private function detectDomain() : string
57
    {
58
        if (isset($_SERVER['HTTP_HOST']) && ! empty($_SERVER['HTTP_HOST'])) {
59
            if (isset($_SERVER['SERVER_PORT'])
60
                && preg_match('/^(?P<host>.*?):(?P<port>\d+)$/', $_SERVER['HTTP_HOST'], $matches)
61
            ) {
62
                return $matches['host'];
63
            }
64
65
            return $_SERVER['HTTP_HOST'];
66
        }
67
68
        if (isset($_SERVER['SERVER_NAME'])) {
69
            return $_SERVER['SERVER_NAME'];
70
        }
71
72
        return self::DEFAULT_DOMAIN;
73
    }
74
}
75