Completed
Push — master ( 419055...1fdeea )
by Hiraku
9s
created

GitHubRequest::promptAuth()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 23
Code Lines 16

Duplication

Lines 23
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 23
loc 23
ccs 0
cts 16
cp 0
rs 8.5906
cc 5
eloc 16
nc 6
nop 2
crap 30
1
<?php
2
/*
3
 * hirak/prestissimo
4
 * @author Hiraku NAKANO
5
 * @license MIT https://github.com/hirak/prestissimo
6
 */
7
namespace Hirak\Prestissimo\Aspects;
8
9
use Composer\IO;
10
use Composer\Util;
11
use Composer\Downloader;
12
13
/**
14
 * Simple Container for http-get request
15
 * GitHub edition
16
 */
17 View Code Duplication
class GitHubRequest extends HttpGetRequest
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
    public function processRFSOption(array $options)
20
    {
21
        if (isset($options['github-token'])) {
22
            $this->query['access_token'] = $options['github-token'];
23
        }
24
    }
25
26
    public function promptAuth(HttpGetResponse $res, IO\IOInterface $io)
27
    {
28
        $httpCode = $res->info['http_code'];
29
        $message = "\nCould not fetch {$this->getURL()}, please create a GitHub OAuth token ";
30
        if (404 === $httpCode) {
31
            $message .= 'to access private repos';
32
        } else {
33
            $message .= 'to go over the API rate limit';
34
        }
35
        $github = new Util\GitHub($io, $this->config, null);
36
        if ($github->authorizeOAuth($this->origin)) {
37
            return true;
38
        }
39
        if ($io->isInteractive() &&
40
            $github->authorizeOAuthInteractively($this->origin, $message)) {
41
            return true;
42
        }
43
44
        throw new Downloader\TransportException(
45
            "Could not authenticate against $this->origin",
46
            401
47
        );
48
    }
49
}
50