Skip to content

Commit

Permalink
More small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpoulter committed Nov 2, 2023
1 parent 0dfac46 commit e90b0b7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/VendConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -49,19 +49,21 @@ 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;

return $this;
}

/**
* @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
Expand All @@ -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;
}
}

0 comments on commit e90b0b7

Please sign in to comment.