From 1c4acf358316689c8c5d215b5f37fdf38e78d0ac Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 21 Jun 2016 11:32:39 +0100 Subject: [PATCH] Refactor code to use RemoteFilesystem facilities for header parsing, refs #5435 --- src/Composer/Repository/Vcs/GitHubDriver.php | 27 ++++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 5c05a218b..04d7321f5 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -325,25 +325,18 @@ class GitHubDriver extends VcsDriver return $this->attemptCloneFallback(); } - $scopes_issued = array(); - $scopes_needed = array(); - if (!is_null($headers = $e->getHeaders())) { - // Check if X-OAuth-Scopes and X-Accepted-OAuth-Scopes should let us in... - foreach ($headers as $header) { - $k = substr($header, 0, strpos($header, ":")); - $v = trim(substr($header, strpos($header, ":")+1)); - switch ($k) { - case 'X-OAuth-Scopes': - $scopes_issued = explode(" ", $v); - break; - case 'X-Accepted-OAuth-Scopes': - $scopes_needed = explode(" ", $v); - break; - } + $scopesIssued = array(); + $scopesNeeded = array(); + if ($headers = $e->getHeaders()) { + if ($scopes = $this->remoteFilesystem->findHeaderValue($headers, 'X-OAuth-Scopes')) { + $scopesIssued = explode(' ', $scopes); + } + if ($scopes = $this->remoteFilesystem->findHeaderValue($headers, 'X-Accepted-OAuth-Scopes')) { + $scopesNeeded = explode(' ', $scopes); } } - $scopes_failed = array_diff($scopes_needed, $scopes_issued); - if (is_null($headers) || count($scopes_failed)) { + $scopesFailed = array_diff($scopesNeeded, $scopesIssued); + if (!$headers || count($scopesFailed)) { $gitHubUtil->authorizeOAuthInteractively($this->originUrl, 'Your GitHub credentials are required to fetch private repository metadata ('.$this->url.')'); }