GitStrings   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseRepositoryName() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GitWrapper\Strings;
6
7
use Nette\Utils\Strings;
8
9
final class GitStrings
10
{
11
    /**
12
     * For example, passing the "[email protected]:cpliakas/git-wrapper.git"
13
     * repository would return "git-wrapper".
14
     */
15
    public static function parseRepositoryName(string $repositoryUrl): string
16
    {
17
        $scheme = parse_url($repositoryUrl, PHP_URL_SCHEME);
18
19
        if ($scheme === null) {
20
            $parts = explode('/', $repositoryUrl);
21
            $path = end($parts);
22
        } else {
23
            $strpos = strpos($repositoryUrl, ':');
24
            $path = Strings::substring($repositoryUrl, $strpos + 1);
25
        }
26
27
        /** @var string $path */
28
        return basename($path, '.git');
29
    }
30
}
31