Completed
Push — master ( 253118...4dbd68 )
by Hiraku
02:17
created

GitHubRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.33%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 1
dl 9
loc 27
ccs 14
cts 15
cp 0.9333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 2
A getURL() 0 12 2

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
 * hirak/prestissimo
4
 * @author Hiraku NAKANO
5
 * @license MIT https://github.com/hirak/prestissimo
6
 */
7
namespace Hirak\Prestissimo;
8
9
use Composer\IO;
10
11
/**
12
 * Simple Container for http-get request
13
 * GitHub edition
14
 */
15
class GitHubRequest extends HttpGetRequest
16
{
17
    const TOKEN_LABEL = 'github-token';
18
19 4 View Code Duplication
    public function __construct($origin, $url, IO\IOInterface $io)
0 ignored issues
show
Duplication introduced by
This method 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...
20
    {
21 4
        parent::__construct($origin, $url, $io);
22 4
        if ($this->password === 'x-oauth-basic') {
23 1
            $this->query['access_token'] = $this->username;
24
            // forbid basic-auth
25 1
            $this->username = $this->password = null;
26 1
        }
27 4
    }
28
29 1
    public function getURL()
30
    {
31 1
        if ($this->maybePublic) {
32 1
            return preg_replace(
33 1
                '%^https://api\.github\.com/repos(/[^/]+/[^/]+/)zipball(.*)%',
34 1
                'https://codeload.github.com$1legacy.zip$2',
35 1
                parent::getURL()
36 1
            );
37
        } else {
38
            return parent::getURL();
39
        }
40
    }
41
}
42