Helpers::getHttpScheme()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 6

Importance

Changes 3
Bugs 1 Features 1
Metric Value
cc 6
eloc 7
c 3
b 1
f 1
nc 4
nop 0
dl 0
loc 14
ccs 5
cts 5
cp 1
crap 6
rs 9.2222
1
<?php
2
3
namespace Enjoys\AssetsCollector;
4
5
use GuzzleHttp\Psr7\Uri;
6
7
final class Helpers
8
{
9
10
    public static function getHttpScheme(): string
11
    {
12
        if (isset($_SERVER['HTTP_SCHEME'])) {
13
            return $_SERVER['HTTP_SCHEME'];
14
        }
15 18
16
        if (isset($_SERVER['HTTPS']) && \strtolower($_SERVER['HTTPS']) !== 'off') {
17 18
            return 'https';
18 2
        }
19
20
        if (isset($_SERVER['SERVER_PORT']) && 443 === (int)$_SERVER['SERVER_PORT']) {
21 16
            return 'https';
22 1
        }
23
        return 'http';
24
    }
25 15
26 1
27
    public static function addVersionToPath(string $path, array $versionQuery): string
28 14
    {
29
        $url = new Uri($path);
30
        parse_str($url->getQuery(), $query);
31
        return $url->withQuery(
32
            http_build_query(array_merge($query, $versionQuery))
33
        )->__toString();
34
    }
35
36
}
37