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 ( 3649b9...b6571f )
by James
04:46
created

Descriptor   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 2
dl 0
loc 92
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B getServedUrls() 0 16 5
B getExposedPath() 0 20 6
A getHost() 0 12 2
B getUriHostAndPath() 0 23 6
1
<?php
2
3
/**
4
 * This file is part of WebHelper Parser.
5
 *
6
 * (c) James <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WebHelper\Parser\Parser;
12
13
use InvalidArgumentException;
14
use Webmozart\PathUtil\Path;
15
use League\Uri\Schemes\Http as HttpUri;
16
17
/**
18
 * Web Helper Universal Descriptor, a.k.a. WHUD.
19
 *
20
 * This is used to find what a server is actually meant to serve
21
 *
22
 * @author James <[email protected]>
23
 */
24
class Descriptor
25
{
26
    private $host;
27
28
    private $paths;
29
30
    /* TODO
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
     * private $proxies;
32
     * private $grants;
33
     */
34
35
    public function __construct($host = '', array $paths = array())
36
    {
37
        $this->host = $host;
38
        $this->paths = $paths;
39
    }
40
41
    public function getServedUrls($path)
42
    {
43
        $isServedAs = [];
44
45
        foreach ($this->paths as $exposedPath => $exposedDirectory) {
46
            if (preg_replace(',/$,', '', $path) == $exposedDirectory ||
47
                Path::isBasePath($exposedDirectory, Path::getDirectory($path))
48
            ) {
49
                $relative = Path::makeRelative($path, $exposedDirectory);
50
                $relative = $relative ? '/'.$relative : '';
51
                $isServedAs[] = $this->getHost().preg_replace(',/$,', '', $exposedPath).$relative;
52
            }
53
        }
54
55
        return $isServedAs;
56
    }
57
58
    public function getExposedPath($url)
59
    {
60
        $isExposedAs = '';
61
        list($host, $path) = $this->getUriHostAndPath($url);
62
63
        if ($host == $this->host) {
64
            foreach ($this->paths as $exposedPath => $exposedDirectory) {
65
                if (preg_replace(',/$,', '', $path) == $exposedPath ||
66
                    Path::isBasePath($exposedPath, Path::getDirectory($path))
67
                ) {
68
                    $relative = Path::makeRelative($path, $exposedPath);
69
                    $relative = $relative ? '/'.$relative : '';
70
                    $isExposedAs = $exposedDirectory.$relative;
71
                    break;
72
                }
73
            }
74
        }
75
76
        return $isExposedAs;
77
    }
78
79
    protected function getHost()
80
    {
81
        $host = $this->host;
82
        $scheme = 'http';
83
84
        if (preg_match('/:443$/', $this->host)) {
85
            $scheme = 'https';
86
            $host = preg_replace('/:443$/', '', $this->host);
87
        }
88
89
        return $scheme.'://'.$host;
90
    }
91
92
    private function getUriHostAndPath($url)
93
    {
94
        try {
95
            $uri = HttpUri::createFromString($url);
96
        } catch (InvalidArgumentException $e) {
97
            return ['', ''];
98
        }
99
100
        $host = $uri->getHost();
101
        $port = $uri->getPort();
102
        if (!$port && $uri->getScheme() == 'https') {
103
            $port = 443;
104
        }
105
        if ($port) {
106
            $host .= ':'.strval($port);
107
        }
108
        $path = $uri->getPath();
109
        if (!$path) {
110
            $path = '/';
111
        }        
112
113
        return [$host, $path];
114
    }
115
}
116