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.

Path   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 24
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 123
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 47 10
A getPath() 0 4 1
A getIsPublic() 0 4 2
A getUserId() 0 4 1
A getIsFolder() 0 4 1
A getIsDocument() 0 4 1
A getModuleName() 0 9 3
A getFolderPath() 0 8 2
A getFolderTreeToUserRoot() 0 17 2
A getFolderTreeFromUserRoot() 0 4 1
1
<?php
2
3
/**
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU Lesser General Public License as published by
6
 *  the Free Software Foundation, either version 3 of the License, or
7
 *  (at your option) any later version.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU Lesser General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU Lesser General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
namespace fkooman\RemoteStorage;
19
20
use fkooman\RemoteStorage\Exception\PathException;
21
22
class Path
23
{
24
    /** @var string */
25
    private $p;
26
27
    /** @var array */
28
    private $pathParts;
29
30
    public function __construct($p)
31
    {
32
        if (!is_string($p)) {
33
            throw new PathException('invalid path: not a string');
34
        }
35
36
        // MUST contain at least one slash and start with it
37
        if (0 !== strpos($p, '/')) {
38
            throw new PathException('invalid path: does not start with /');
39
        }
40
41
        // MUST NOT contain encoded "/"
42
        if (false !== stripos($p, '%2f')) {
43
            throw new PathException('invalid path: contains encoded "/"');
44
        }
45
46
        // MUST NOT contain encoded "\0"
47
        if (false !== strpos($p, '%00')) {
48
            throw new PathException('invalid path: contains encoded "\0"');
49
        }
50
51
        // MUST NOT contain ".."
52
        if (false !== strpos($p, '..')) {
53
            throw new PathException('invalid path: contains ..');
54
        }
55
56
        // MUST NOT contain "%2e%2e"
57
        if (false !== stripos($p, '%2e%2e')) {
58
            throw new PathException('invalid path: contains encoded ".."');
59
        }
60
61
        // MUST NOT contain "//"
62
        if (false !== strpos($p, '//')) {
63
            throw new PathException('invalid path: contains //');
64
        }
65
66
        // MUST contain a user
67
        $pathParts = explode('/', $p);
68
        if (count($pathParts) < 3) {
69
            throw new PathException('invalid path: no user specified');
70
        }
71
72
        foreach ($pathParts as $pathPart) {
73
            $this->pathParts[] = rawurldecode($pathPart);
74
        }
75
        $this->p = implode('/', $this->pathParts);
76
    }
77
78
    public function getPath()
79
    {
80
        return $this->p;
81
    }
82
83
    public function getIsPublic()
84
    {
85
        return count($this->pathParts) > 3 && 'public' === $this->pathParts[2];
86
    }
87
88
    public function getUserId()
89
    {
90
        return $this->pathParts[1];
91
    }
92
93
    public function getIsFolder()
94
    {
95
        return empty($this->pathParts[count($this->pathParts) - 1]);
96
    }
97
98
    public function getIsDocument()
99
    {
100
        return !$this->getIsFolder();
101
    }
102
103
    public function getModuleName()
104
    {
105
        $moduleNamePosition = $this->getIsPublic() ? 3 : 2;
106
        if (count($this->pathParts) > $moduleNamePosition + 1) {
107
            return $this->pathParts[$moduleNamePosition];
108
        }
109
110
        return false;
111
    }
112
113
    public function getFolderPath()
114
    {
115
        if ($this->getIsFolder()) {
116
            return $this->p;
117
        }
118
119
        return substr($this->p, 0, strrpos($this->p, '/') + 1);
120
    }
121
122
    public function getFolderTreeToUserRoot()
123
    {
124
        $p = $this->getFolderPath();
125
        do {
126
            $folderTree[] = $p;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$folderTree was never initialized. Although not strictly required by PHP, it is generally a good practice to add $folderTree = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
127
128
            // remove from last "/" to previous "/", e.g.:
129
            // "/foo/bar/baz/" -> "/foo/bar/"
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
130
131
            // remove the last "/"
132
            $p = substr($p, 0, strlen($p) - 1);
133
            // remove everything after the now last "/"
134
            $p = substr($p, 0, strrpos($p, '/') + 1);
135
        } while (substr_count($p, '/') > 1);
136
137
        return $folderTree;
138
    }
139
140
    public function getFolderTreeFromUserRoot()
141
    {
142
        return array_reverse($this->getFolderTreeToUserRoot());
143
    }
144
}
145