Completed
Push — master ( 6acfe1...0042b2 )
by Radu
11:51 queued 10s
created

RequestHelper::getRemoteAddress()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Helpers;
6
7
final class RequestHelper
8
{
9
    public static function getRemoteAddress(): string
10
    {
11
        if (PhpHelper::isCli()) {
12
            return \gethostbyname(\php_uname('n'));
13
        }
14
15
        // phpcs:ignore SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable
16
        if (\array_key_exists('REMOTE_ADDR', $_SERVER)) {
17
            // phpcs:ignore SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable
18
            return \WebServCo\Framework\Utils\Request::sanitizeString($_SERVER['REMOTE_ADDR']);
19
        }
20
21
        return '';
22
    }
23
}
24