Code Duplication    Length = 33-33 lines in 2 locations

src/Aspects/GitHubRequest.php 1 location

@@ 17-49 (lines=33) @@
14
 * Simple Container for http-get request
15
 * GitHub edition
16
 */
17
class GitHubRequest extends HttpGetRequest
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

src/Aspects/GitLabRequest.php 1 location

@@ 17-49 (lines=33) @@
14
 * Simple Container for http-get request
15
 * GitLab edition
16
 */
17
class GitLabRequest extends HttpGetRequest
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