Completed
Pull Request — master (#61)
by Hiraku
02:17
created

GitLabRequest::getCurlOpts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 5
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
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
 * GitLab edition
16
 */
17 View Code Duplication
class GitLabRequest 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['gitlab-token'])) {
22
            $this->query['access_token'] = $options['gitlab-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()}, enter your $this->origin credentials ";
30
        if (401 === $httpCode) {
31
            $message .= 'to access private repos';
32
        } else {
33
            $message .= 'to go over the API rate limit';
34
        }
35
        $gitlab = new Util\GitLab($io, $this->config, null);
36
        if ($gitlab->authorizeOAuth($this->origin)) {
37
            return true;
38
        }
39
        if ($io->isInteractive() &&
40
            $gitlab->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