From 3ccaac619b9853a0bf6edcc59ea448b8c1f1ade8 Mon Sep 17 00:00:00 2001 From: Stefan Grootscholten Date: Sun, 29 Jan 2017 15:35:50 +0100 Subject: [PATCH] Refactor the getRepoData method to not throw an Exception --- src/Composer/Repository/Vcs/BitbucketDriver.php | 5 +++-- .../Vcs/BitbucketFallbackException.php | 17 ----------------- .../Repository/Vcs/GitBitbucketDriver.php | 4 +--- .../Repository/Vcs/HgBitbucketDriver.php | 4 +--- 4 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 src/Composer/Repository/Vcs/BitbucketFallbackException.php diff --git a/src/Composer/Repository/Vcs/BitbucketDriver.php b/src/Composer/Repository/Vcs/BitbucketDriver.php index e2497aa72..ba1851f53 100644 --- a/src/Composer/Repository/Vcs/BitbucketDriver.php +++ b/src/Composer/Repository/Vcs/BitbucketDriver.php @@ -77,7 +77,7 @@ abstract class BitbucketDriver extends VcsDriver * Attempts to fetch the repository data via the BitBucket API and * sets some parameters which are used in other methods * - * @return void + * @return bool */ protected function getRepoData() { @@ -94,7 +94,7 @@ abstract class BitbucketDriver extends VcsDriver $repoData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource, true), $resource); if ($this->fallbackDriver) { - throw new BitbucketFallbackException(); + return false; } $this->parseCloneUrls($repoData['links']['clone']); @@ -104,6 +104,7 @@ abstract class BitbucketDriver extends VcsDriver $this->homeUrl = $repoData['links']['html']['href']; $this->website = $repoData['website']; $this->vcsType = $repoData['scm']; + return true; } /** diff --git a/src/Composer/Repository/Vcs/BitbucketFallbackException.php b/src/Composer/Repository/Vcs/BitbucketFallbackException.php deleted file mode 100644 index 063bb4c10..000000000 --- a/src/Composer/Repository/Vcs/BitbucketFallbackException.php +++ /dev/null @@ -1,17 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Repository\Vcs; - -class BitbucketFallbackException extends \RuntimeException -{ -} diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index 82fe69028..c8a5c9905 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -30,9 +30,7 @@ class GitBitbucketDriver extends BitbucketDriver } if (null === $this->rootIdentifier) { - try { - $this->getRepoData(); - } catch (BitbucketFallbackException $e) { + if (! $this->getRepoData()) { return $this->fallbackDriver->getRootIdentifier(); } diff --git a/src/Composer/Repository/Vcs/HgBitbucketDriver.php b/src/Composer/Repository/Vcs/HgBitbucketDriver.php index e908f9ce6..8324f22ac 100644 --- a/src/Composer/Repository/Vcs/HgBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/HgBitbucketDriver.php @@ -30,9 +30,7 @@ class HgBitbucketDriver extends BitbucketDriver } if (null === $this->rootIdentifier) { - try { - $this->getRepoData(); - } catch (BitbucketFallbackException $e) { + if (! $this->getRepoData()) { return $this->fallbackDriver->getRootIdentifier(); }