Completed
Push — master ( 651eb5...e7f95e )
by Tomáš
16:52 queued 15:34
created

GitStrings::parseRepositoryName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GitWrapper\Strings;
6
7
final class GitStrings
8
{
9
    /**
10
     * For example, passing the "[email protected]:cpliakas/git-wrapper.git"
11
     * repository would return "git-wrapper".
12
     */
13
    public static function parseRepositoryName(string $repositoryUrl): string
14
    {
15
        $scheme = parse_url($repositoryUrl, PHP_URL_SCHEME);
16
17
        if ($scheme === null) {
18
            $parts = explode('/', $repositoryUrl);
19
            $path = end($parts);
20
        } else {
21
            $strpos = strpos($repositoryUrl, ':');
22
            $path = substr($repositoryUrl, $strpos + 1);
23
        }
24
25
        /** @var string $path */
26
        return basename($path, '.git');
27
    }
28
}
29