From d6b736ba25d4fd56dd87408e41209977573f741c Mon Sep 17 00:00:00 2001 From: Michael Stilkerich Date: Wed, 3 Aug 2022 19:04:49 +0200 Subject: [PATCH] Stop discovery when an addressbook home is discovered first - If there are no addressbooks under the addressbook home, this is fine and we return an empty list. - If we do not manage to discover an addressbook home, throw an exception as would be expected by the function specification instead of an empty array. --- src/Services/Discovery.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Services/Discovery.php b/src/Services/Discovery.php index 4cb0579..7f249fe 100644 --- a/src/Services/Discovery.php +++ b/src/Services/Discovery.php @@ -132,9 +132,9 @@ public function discoverAddressbooks(Account $account): array } } - if (count($addressbooks) > 0) { - break 2; - } + // We found a valid addressbook home. If it contains no addressbooks, this is fine and the + // result of the discovery is an empty set. + return $addressbooks; } catch (\Exception $e) { Config::$logger->info("Exception while querying addressbooks: " . $e->getMessage()); } @@ -143,7 +143,7 @@ public function discoverAddressbooks(Account $account): array } } - return $addressbooks; + throw new \Exception("Could not determine the addressbook home"); } /**