From 5d228f179a680075e117fe168b1307d402fe3fe7 Mon Sep 17 00:00:00 2001 From: James Armes Date: Mon, 6 Feb 2017 01:06:22 -0500 Subject: [PATCH] Throw an exception on autodiscovery failure. --- CHANGELOG.md | 3 +++ examples/autodiscover/basic.php | 5 ----- .../autodiscover/certificate-authority.php | 5 ----- src/Autodiscover.php | 21 +++++++------------ 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01b7d693..3017518d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] +### Changed +- Autodiscovery failure now throws a RuntimeException. + ## 1.0.0-beta.3 - 2017-01-21 ### Added diff --git a/examples/autodiscover/basic.php b/examples/autodiscover/basic.php index 83d5a463..70ca0171 100644 --- a/examples/autodiscover/basic.php +++ b/examples/autodiscover/basic.php @@ -22,8 +22,3 @@ // Simplest usage, no special options. $client = Autodiscover::getEWS($email, $password); - -// If autodiscovery failed, throw an exception. -if (!$client) { - throw new Exception('Autodiscovery failed.'); -} diff --git a/examples/autodiscover/certificate-authority.php b/examples/autodiscover/certificate-authority.php index 26972eef..b1dda8cb 100644 --- a/examples/autodiscover/certificate-authority.php +++ b/examples/autodiscover/certificate-authority.php @@ -16,8 +16,3 @@ $discovery = new Autodiscover($email, $password); $discovery->setCAInfo($ca_path); $client = $discovery->newEWS(); - -// If autodiscovery failed, throw an exception. -if (!$client) { - throw new Exception('Autodiscovery failed.'); -} diff --git a/src/Autodiscover.php b/src/Autodiscover.php index 554265c6..bf84452f 100644 --- a/src/Autodiscover.php +++ b/src/Autodiscover.php @@ -238,10 +238,11 @@ public function __construct($email, $password, $username = null) * Execute the full discovery chain of events in the correct sequence * until a valid response is received, or all methods have failed. * - * @return integer|boolean - * One of the AUTODISCOVERED_VIA_* constants or false on failure. + * @return integer + * One of the AUTODISCOVERED_VIA_* constants. * - * @todo Throw an exception on failure. + * @throws \RuntimeException + * When all autodiscovery methods fail. */ public function discover() { @@ -259,6 +260,10 @@ public function discover() $result = $this->trySRVRecord(); } + if ($result === false) { + throw new \RuntimeException('Autodiscovery failed.'); + } + return $result; } @@ -304,8 +309,6 @@ public function skipSSLVerification($skip = true) * * @param string $version_hex * Hexadecimal version string. - * - * @todo Update to include Exchange 2013 versions. */ public function parseServerVersion($version_hex) { @@ -413,8 +416,6 @@ public static function getEWS($email, $password, $username = null) * * @return integer|boolean * One of the AUTODISCOVERED_VIA_* constants or false on failure. - * - * @todo Throw an exception on failure. */ public function tryTLD() { @@ -428,8 +429,6 @@ public function tryTLD() * * @return integer|boolean * One of the AUTODISCOVERED_VIA_* constants or false on failure. - * - * @todo Throw an exception on failure. */ public function trySubdomain() { @@ -445,8 +444,6 @@ public function trySubdomain() * * @return integer|boolean * One of the AUTODISCOVERED_VIA_* constants or false on failure. - * - * @todo Throw an exception on failure. */ public function trySubdomainUnauthenticatedGet() { @@ -490,8 +487,6 @@ public function trySubdomainUnauthenticatedGet() * * @return integer|boolean * The value of self::AUTODISCOVERED_VIA_SRV_RECORD or false. - * - * @todo Throw an exception on failure. */ public function trySRVRecord() {