Completed
Push — master ( f0c745...274b6a )
by Sergi Tur
01:40
created

InteractsWithLocalGithub   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 8
loc 24
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRepoFromGithubConfig() 8 16 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 Acacha\ForgePublish\Commands\Traits;
4
5
/**
6
 * Trait InteractsWithLocalGithub.
7
 *
8
 * @package Acacha\ForgePublish\Commands\Traits
9
 */
10
trait InteractsWithLocalGithub
11
{
12
    /**
13
     * Get github repo from github.
14
     *
15
     * @return string
16
     */
17
    protected function getRepoFromGithubConfig()
18
    {
19
        $remote = `git remote get-url origin 2> /dev/null`;
20
        if (! starts_with($remote, ['[email protected]:','https://github.com/'])) {
21
            return '';
22
        }
23
24 View Code Duplication
        if (starts_with($remote, '[email protected]:')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
25
            // [email protected]:acacha/forge-publish.git
26
            return explode('.', explode(":", $remote)[1])[0];
27
        }
28 View Code Duplication
        if (starts_with($remote, 'https://github.com/')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
29
//            https://github.com/acacha/llum.git
30
            return explode('.', str_replace('https://github.com/', '', $remote))[0];
31
        }
32
    }
33
}