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.

Str   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A startsWith() 0 8 3
A removeFromStart() 0 8 2
A replaceFirst() 0 10 2
A ensureLeft() 0 8 2
A ensureRight() 0 8 2
1
<?php
2
3
namespace Spatie\Menu\Helpers;
4
5
class Str
6
{
7
    public static function startsWith(string $haystack, string $needle): bool
8
    {
9
        if ($needle != '' && substr($haystack, 0, strlen($needle)) === $needle) {
10
            return true;
11
        }
12
13
        return false;
14
    }
15
16
    public static function removeFromStart(string $remove, string $subject): string
17
    {
18
        if (! self::startsWith($subject, $remove)) {
19
            return $subject;
20
        }
21
22
        return self::replaceFirst($remove, '', $subject);
23
    }
24
25
    public static function replaceFirst(string $search, string $replace, string $subject): string
26
    {
27
        $position = strpos($subject, $search);
28
29
        if ($position !== false) {
30
            return substr_replace($subject, $replace, $position, strlen($search));
31
        }
32
33
        return $subject;
34
    }
35
36
    public static function ensureLeft(string $pattern, string $subject): string
37
    {
38
        if (strpos($subject, $pattern) === 0) {
39
            return $subject;
40
        }
41
42
        return $pattern.$subject;
43
    }
44
45
    public static function ensureRight(string $pattern, string $subject): string
46
    {
47
        if (strrpos($subject, $pattern) === strlen($subject) - 1) {
48
            return $subject;
49
        }
50
51
        return $subject.$pattern;
52
    }
53
}
54