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 ( e52ef6...deed81 )
by Sebastian
15:30
created

ExactUrlChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 41
loc 41
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 38 38 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Spatie\Menu;
4
5
use Spatie\Url\Url;
6
use Spatie\Menu\Helpers\Str;
7
8 View Code Duplication
class ExactUrlChecker
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    public static function check(string $url, string $requestUrl, string $rootUrl = '/'): bool
11
    {
12
        $url = Url::fromString($url);
13
        $requestUrl = Url::fromString($requestUrl);
14
15
        // If the hosts don't match, this url isn't active.
16
        if ($url->getHost() !== $requestUrl->getHost()) {
17
            return false;
18
        }
19
20
        $rootUrl = Str::ensureLeft('/', $rootUrl);
21
22
        // All paths used in this method should be terminated by a /
23
        // otherwise startsWith at the end will be too greedy and
24
        // also matches items which are on the same level
25
        $rootUrl = Str::ensureRight('/', $rootUrl);
26
27
        $itemPath = Str::ensureRight('/', $url->getPath());
28
29
        // If this url doesn't start with the rootUrl, it's inactive.
30
        if (! Str::startsWith($itemPath, $rootUrl)) {
31
            return false;
32
        }
33
34
        $matchPath = Str::ensureRight('/', $requestUrl->getPath());
35
36
        // For the next comparisons we just need the paths, and we'll remove
37
        // the rootUrl first.
38
        $itemPath = Str::removeFromStart($rootUrl, $itemPath);
39
        $matchPath = Str::removeFromStart($rootUrl, $matchPath);
40
41
        // If this url is an exact match for the url we're matching with, it's exact-active.
42
        if ($matchPath === $itemPath) {
43
            return true;
44
        }
45
46
        return false;
47
    }
48
}
49