Helpers::addVersionToPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 1
cts 1
cp 1
crap 1
rs 10
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