Skip to content

Commit

Permalink
Type annotations for Account
Browse files Browse the repository at this point in the history
  • Loading branch information
mstilkerich committed Jan 30, 2021
1 parent c750381 commit a975eaa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions src/Account.php
Expand Up @@ -154,19 +154,20 @@ public function __toString(): string
*/
public function findCurrentUserPrincipal(string $contextPathUri): ?string
{
$princUrl = null;

try {
$client = $this->getClient();
$result = $client->findProperties($contextPathUri, [XmlEN::CURUSRPRINC]);

$princUrl = $result[0]["props"][XmlEN::CURUSRPRINC] ?? null;

if (isset($princUrl)) {
if (isset($result[0]["props"][XmlEN::CURUSRPRINC])) {
/** @var string Ensured by deserializer function */
$princUrl = $result[0]["props"][XmlEN::CURUSRPRINC];
$princUrl = CardDavClient::concatUrl($result[0]["uri"], $princUrl);
Config::$logger->info("principal URL: $princUrl");
}
} catch (\Exception $e) {
Config::$logger->info("Exception while querying current-user-principal: " . $e->getMessage());
$princUrl = null;
}

return $princUrl;
Expand All @@ -191,21 +192,25 @@ public function findCurrentUserPrincipal(string $contextPathUri): ?string
*/
public function findAddressbookHome(string $principalUri): ?string
{
$addressbookHomeUri = null;

try {
$client = $this->getClient();
$result = $client->findProperties($principalUri, [XmlEN::ABOOK_HOME]);

// FIXME per RFC several home locations could be returned, but we currently only use one. However, it is
// rather unlikely that there would be several addressbook home locations.
$addressbookHomeUri = $result[0]["props"][XmlEN::ABOOK_HOME][0] ?? null;

if (isset($addressbookHomeUri)) {
$addressbookHomeUri = CardDavClient::concatUrl($result[0]["uri"], $addressbookHomeUri);
Config::$logger->info("addressbook home: $addressbookHomeUri");
if (isset($result[0]["props"][XmlEN::ABOOK_HOME])) {
/** @var list<string> $hrefs */
$hrefs = $result[0]["props"][XmlEN::ABOOK_HOME];
if (!empty($hrefs)) {
$addressbookHomeUri = $hrefs[0];
$addressbookHomeUri = CardDavClient::concatUrl($result[0]["uri"], $addressbookHomeUri);
Config::$logger->info("addressbook home: $addressbookHomeUri");
}
}
} catch (\Exception $e) {
Config::$logger->info("Exception while querying addressbook-home-set: " . $e->getMessage());
$addressbookHomeUri = null;
}

return $addressbookHomeUri;
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClientAdapterGuzzle.php
Expand Up @@ -238,7 +238,7 @@ private function prepareGuzzleOptions(array $options = [], bool $doAuth = false)
}
}

if ( ($options["allow_redirects"] ?? true) === false) {
if (($options["allow_redirects"] ?? true) === false) {
$guzzleOptions["allow_redirects"] = false;
} else {
$guzzleOptions["allow_redirects"] = [
Expand Down

0 comments on commit a975eaa

Please sign in to comment.