From 63b74c1717e1c27940b958acef4b60192de6e339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gamez?= Date: Tue, 25 Apr 2017 12:03:25 +0200 Subject: [PATCH] Be more informative when credentials have not been found --- CHANGELOG.md | 5 +++ .../Exception/CredentialsNotFound.php | 34 +++++++++++++++++++ src/Firebase/Factory.php | 5 +-- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/Firebase/Exception/CredentialsNotFound.php diff --git a/CHANGELOG.md b/CHANGELOG.md index a69e617b..8a2ca210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## Unreleased + +* When the credentials file has not been found, a `CredentialsNotFound` exception is thrown, + including the information which paths have been tried. + ## 3.0.0 - 2017-04-22 * Moved all classes inside the `Kreait` namespace to avoid possible conflicts with official Firebase PHP libraries diff --git a/src/Firebase/Exception/CredentialsNotFound.php b/src/Firebase/Exception/CredentialsNotFound.php new file mode 100644 index 00000000..c8acd5d4 --- /dev/null +++ b/src/Firebase/Exception/CredentialsNotFound.php @@ -0,0 +1,34 @@ +triedPaths = $triedPaths; + } + + /** + * @return \string[] + */ + public function getTriedPaths(): array + { + return $this->triedPaths; + } +} diff --git a/src/Firebase/Factory.php b/src/Firebase/Factory.php index 4bcbdb98..5282b279 100644 --- a/src/Firebase/Factory.php +++ b/src/Firebase/Factory.php @@ -96,10 +96,7 @@ private function getServiceAccount(): ServiceAccount } // @codeCoverageIgnoreEnd - throw new LogicException(sprintf( - 'No service account has been found. Please set the path to a service account credentials file with %s::%s()', - static::class, 'withCredentials($path)' - )); + throw new Firebase\Exception\CredentialsNotFound($this->credentialPaths); } private function getServiceAccountCandidates(): array