Completed
Pull Request — master (#80)
by Hiraku
02:20
created

GitHubRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 39.13 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 1
dl 9
loc 23
ccs 13
cts 13
cp 1
rs 10

2 Methods

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

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
        return preg_replace(
32 1
            '%^https://api\.github\.com/repos(/[^/]+/[^/]+/)zipball(.*)%',
33 1
            'https://codeload.github.com$1legacy.zip$2',
34 1
            parent::getURL()
35 1
        );
36
    }
37
}
38