Code Duplication    Length = 39-39 lines in 2 locations

src/Aspects/GitHubRequest.php 1 location

@@ 18-56 (lines=39) @@
15
 * Simple Container for http-get request
16
 * GitHub edition
17
 */
18
class GitHubRequest extends HttpGetRequest
19
{
20
    public function processRFSOption(array $options)
21
    {
22
        if (isset($options['github-token'])) {
23
            $this->query['access_token'] = $options['github-token'];
24
        }
25
    }
26
27
    public function getCurlOpts()
28
    {
29
        $curlOpts = parent::getCurlOpts();
30
        return $curlOpts;
31
    }
32
33
    public function promptAuth(HttpGetResponse $res, CConfig $config, IO\IOInterface $io)
34
    {
35
        $httpCode = $res->info['http_code'];
36
        $message = "\nCould not fetch {$this->getURL()}, please create a GitHub OAuth token ";
37
        if (404 === $httpCode) {
38
            $message .= 'to access private repos';
39
        } else {
40
            $message .= 'to go over the API rate limit';
41
        }
42
        $github = new Util\GitHub($io, $config, null);
43
        if ($github->authorizeOAuth($this->origin)) {
44
            return true;
45
        }
46
        if ($io->isInteractive() &&
47
            $github->authorizeOAuthInteractively($this->origin, $message)) {
48
            return true;
49
        }
50
51
        throw new Downloader\TransportException(
52
            "Could not authenticate against $this->origin",
53
            401
54
        );
55
    }
56
}
57

src/Aspects/GitLabRequest.php 1 location

@@ 18-56 (lines=39) @@
15
 * Simple Container for http-get request
16
 * GitLab edition
17
 */
18
class GitLabRequest extends HttpGetRequest
19
{
20
    public function processRFSOption(array $options)
21
    {
22
        if (isset($options['gitlab-token'])) {
23
            $this->query['access_token'] = $options['gitlab-token'];
24
        }
25
    }
26
27
    public function getCurlOpts()
28
    {
29
        $curlOpts = parent::getCurlOpts();
30
        return $curlOpts;
31
    }
32
33
    public function promptAuth(HttpGetResponse $res, CConfig $config, IO\IOInterface $io)
34
    {
35
        $httpCode = $res->info['http_code'];
36
        $message = "\nCould not fetch {$this->getURL()}, enter your $this->origin credentials ";
37
        if (401 === $httpCode) {
38
            $message .= 'to access private repos';
39
        } else {
40
            $message .= 'to go over the API rate limit';
41
        }
42
        $gitlab = new Util\GitLab($io, $config, null);
43
        if ($gitlab->authorizeOAuth($this->origin)) {
44
            return true;
45
        }
46
        if ($io->isInteractive() &&
47
            $gitlab->authorizeOAuthInteractively($this->origin, $message)) {
48
            return true;
49
        }
50
51
        throw new Downloader\TransportException(
52
            "Could not authenticate against $this->origin",
53
            401
54
        );
55
    }
56
}
57