From e90b0b77d618fb5a4db14b7fd2ba9064befd755b Mon Sep 17 00:00:00 2001 From: Matthew Poulter Date: Thu, 2 Nov 2023 08:14:11 +0100 Subject: [PATCH] More small improvements --- src/VendConnector.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/VendConnector.php b/src/VendConnector.php index 9ba812b..6706a28 100644 --- a/src/VendConnector.php +++ b/src/VendConnector.php @@ -21,9 +21,9 @@ abstract class VendConnector extends Connector protected ?string $domainPrefix; /** - * @var callable(): ?\Saloon\Contracts\Authenticator + * @var ?callable(static): ?\Saloon\Contracts\Authenticator */ - protected $defaultAuth; + protected $defaultAuth = null; public function __construct( ?string $clientId = null, @@ -49,7 +49,7 @@ public function resolveBaseUrl(): string return "https://{$this->domainPrefix}.vendhq.com/api"; } - public function withDomainPrefix(string $domainPrefix): static + public function withDomainPrefix(?string $domainPrefix): static { $this->domainPrefix = $domainPrefix; @@ -57,11 +57,13 @@ public function withDomainPrefix(string $domainPrefix): static } /** - * @param callable(): ?\Saloon\Contracts\Authenticator $callable + * @param callable(static): ?\Saloon\Contracts\Authenticator $callable */ public function authenticateWith(callable $callable): static { $this->defaultAuth = $callable; + + return $this; } protected function defaultHeaders(): array @@ -81,6 +83,6 @@ protected function defaultOauthConfig(): OAuthConfig protected function defaultAuth(): ?Authenticator { - return isset($this->defaultAuth) ? ($this->defaultAuth)() : null; + return is_callable($this->defaultAuth) ? ($this->defaultAuth)($this) : null; } }