diff --git a/src/Picqer/Financials/Exact/Connection.php b/src/Picqer/Financials/Exact/Connection.php index 12e56d00..d8c543c3 100644 --- a/src/Picqer/Financials/Exact/Connection.php +++ b/src/Picqer/Financials/Exact/Connection.php @@ -1,5 +1,7 @@ client) { return $this->client; @@ -180,10 +134,8 @@ private function client() /** * Insert a custom Guzzle client. - * - * @param Client $client */ - public function setClient($client) + public function setClient(Client $client): void { $this->client = $client; } @@ -200,10 +152,8 @@ public function insertMiddleWare($middleWare) /** * @throws ApiException - * - * @return Client */ - public function connect() + public function connect(): Client { // Redirect for authorization if needed (no access token or refresh token given) if ($this->needsAuthentication()) { @@ -212,9 +162,7 @@ public function connect() $this->checkOrAcquireAccessToken(); - $client = $this->client(); - - return $client; + return $this->client(); } /** @@ -222,7 +170,7 @@ public function connect() * * @throws \Picqer\Financials\Exact\ApiException */ - public function checkOrAcquireAccessToken() + public function checkOrAcquireAccessToken(): void { // If access token is not set or token has expired, acquire new token if (empty($this->accessToken) || $this->tokenHasExpired()) { @@ -241,7 +189,7 @@ public function checkOrAcquireAccessToken() * * @return Request */ - private function createRequest($method, $endpoint, $body = null, array $params = [], array $headers = []) + private function createRequest($method, $endpoint, $body = null, array $params = [], array $headers = []): Request { // Add default json headers to the request $headers = array_merge($headers, [ @@ -264,9 +212,7 @@ private function createRequest($method, $endpoint, $body = null, array $params = } // Create the request - $request = new Request($method, $endpoint, $headers, $body); - - return $request; + return new Request($method, $endpoint, $headers, $body); } /** @@ -405,10 +351,7 @@ public function delete($url) } } - /** - * @return string - */ - public function getAuthUrl() + public function getAuthUrl(): string { return $this->baseUrl . $this->authUrl . '?' . http_build_query([ 'client_id' => $this->exactClientId, @@ -459,7 +402,7 @@ public function setRefreshToken($refreshToken) $this->refreshToken = $refreshToken; } - public function redirectForAuthorization() + public function redirectForAuthorization(): void { $authUrl = $this->getAuthUrl(); header('Location: ' . $authUrl); @@ -474,26 +417,17 @@ public function setRedirectUrl($redirectUrl) $this->redirectUrl = $redirectUrl; } - /** - * @param bool $forceLogin - */ - public function setForceLogin($forceLogin) + public function setForceLogin(bool $forceLogin): void { $this->forceLogin = $forceLogin; } - /** - * @param string $state - */ - public function setState(string $state) + public function setState(string $state): void { $this->state = $state; } - /** - * @return bool - */ - public function needsAuthentication() + public function needsAuthentication(): bool { return empty($this->refreshToken) && empty($this->authorizationCode); } @@ -628,7 +562,7 @@ public function getAccessToken() return $this->accessToken; } - private function acquireAccessToken() + private function acquireAccessToken(): void { try { if (is_callable($this->acquireAccessTokenLockCallback)) { @@ -694,10 +628,8 @@ private function acquireAccessToken() * Translates expires_in to a Unix timestamp. * * @param string $expiresIn number of seconds until the token expires - * - * @return int */ - private function getTimestampFromExpiresIn($expiresIn) + private function getTimestampFromExpiresIn($expiresIn): int { if (! ctype_digit($expiresIn)) { throw new \InvalidArgumentException('Function requires a numeric expires value'); @@ -706,10 +638,7 @@ private function getTimestampFromExpiresIn($expiresIn) return time() + (int) $expiresIn; } - /** - * @return int the Unix timestamp at which the access token expires - */ - public function getTokenExpires() + public function getTokenExpires(): int { return $this->tokenExpires; } @@ -722,7 +651,7 @@ public function setTokenExpires($tokenExpires) $this->tokenExpires = $tokenExpires; } - private function tokenHasExpired() + private function tokenHasExpired(): bool { if (empty($this->tokenExpires)) { return true; @@ -770,7 +699,7 @@ public function setDivision($division) /** * @param callable $callback */ - public function setAcquireAccessTokenLockCallback($callback) + public function setAcquireAccessTokenLockCallback($callback): void { $this->acquireAccessTokenLockCallback = $callback; } @@ -778,7 +707,7 @@ public function setAcquireAccessTokenLockCallback($callback) /** * @param callable $callback */ - public function setAcquireAccessTokenUnlockCallback($callback) + public function setAcquireAccessTokenUnlockCallback($callback): void { $this->acquireAccessTokenUnlockCallback = $callback; } @@ -786,7 +715,7 @@ public function setAcquireAccessTokenUnlockCallback($callback) /** * @param callable $callback */ - public function setTokenUpdateCallback($callback) + public function setTokenUpdateCallback($callback): void { $this->tokenUpdateCallback = $callback; } @@ -794,7 +723,7 @@ public function setTokenUpdateCallback($callback) /** * @param callable $callback */ - public function setRefreshAccessTokenCallback($callback) + public function setRefreshAccessTokenCallback($callback): void { $this->refreshAccessTokenCallback = $callback; } @@ -806,7 +735,7 @@ public function setRefreshAccessTokenCallback($callback) * * @throws ApiException */ - private function parseExceptionForErrorMessages(Exception $e) + private function parseExceptionForErrorMessages(Exception $e): void { if (! $e instanceof BadResponseException) { throw new ApiException($e->getMessage(), 0, $e); @@ -834,73 +763,64 @@ private function parseExceptionForErrorMessages(Exception $e) } /** - * @return int|null The maximum number of API calls that your app is permitted to make per company, per day + * Return the maximum number of API calls that your app is permitted to make per company, per day. */ - public function getDailyLimit() + public function getDailyLimit(): ?int { return $this->dailyLimit; } /** - * @return int|null The remaining number of API calls that your app is permitted to make for a company, per day + * Return the remaining number of API calls that your app is permitted to make for a company, per day. */ - public function getDailyLimitRemaining() + public function getDailyLimitRemaining(): ?int { return $this->dailyLimitRemaining; } /** - * @return int|null The time at which the rate limit window resets in UTC epoch milliseconds + * Return the time at which the rate limit window resets in UTC epoch milliseconds. */ - public function getDailyLimitReset() + public function getDailyLimitReset(): ?int { return $this->dailyLimitReset; } /** - * @return int|null The maximum number of API calls that your app is permitted to make per company, per minute + * Return the maximum number of API calls that your app is permitted to make per company, per minute. */ - public function getMinutelyLimit() + public function getMinutelyLimit(): ?int { return $this->minutelyLimit; } /** - * @return int|null The remaining number of API calls that your app is permitted to make for a company, per minute + * Return the remaining number of API calls that your app is permitted to make for a company, per minute. */ - public function getMinutelyLimitRemaining() + public function getMinutelyLimitRemaining(): ?int { return $this->minutelyLimitRemaining; } /** - * @return int|null The time at which the minutely rate limit window resets in UTC epoch milliseconds + * Return the time at which the minutely rate limit window resets in UTC epoch milliseconds. */ - public function getMinutelyLimitReset() + public function getMinutelyLimitReset(): ?int { return $this->minutelyLimitReset; } - /** - * @return string - */ - protected function getBaseUrl() + protected function getBaseUrl(): string { return $this->baseUrl; } - /** - * @return string - */ - private function getApiUrl() + private function getApiUrl(): string { return $this->baseUrl . $this->apiUrl; } - /** - * @return string - */ - private function getTokenUrl() + private function getTokenUrl(): string { return $this->baseUrl . $this->tokenUrl; } @@ -908,39 +828,28 @@ private function getTokenUrl() /** * Set base URL for different countries according to * https://developers.exactonline.com/#Exact%20Online%20sites.html. - * - * @param string $baseUrl */ - public function setBaseUrl($baseUrl) + public function setBaseUrl(string $baseUrl): void { $this->baseUrl = $baseUrl; } - /** - * @param string $apiUrl - */ - public function setApiUrl($apiUrl) + public function setApiUrl(string $apiUrl): void { $this->apiUrl = $apiUrl; } - /** - * @param string $authUrl - */ - public function setAuthUrl($authUrl) + public function setAuthUrl(string $authUrl): void { $this->authUrl = $authUrl; } - /** - * @param string $tokenUrl - */ - public function setTokenUrl($tokenUrl) + public function setTokenUrl(string $tokenUrl): void { $this->tokenUrl = $tokenUrl; } - private function extractRateLimits(Response $response) + private function extractRateLimits(Response $response): void { $this->dailyLimit = (int) $response->getHeaderLine('X-RateLimit-Limit'); $this->dailyLimitRemaining = (int) $response->getHeaderLine('X-RateLimit-Remaining'); @@ -951,7 +860,7 @@ private function extractRateLimits(Response $response) $this->minutelyLimitReset = (int) $response->getHeaderLine('X-RateLimit-Minutely-Reset'); } - protected function waitIfMinutelyRateLimitHit() + protected function waitIfMinutelyRateLimitHit(): void { if (! $this->waitOnMinutelyRateLimitHit) { return; @@ -973,7 +882,7 @@ protected function waitIfMinutelyRateLimitHit() } } - public function setWaitOnMinutelyRateLimitHit(bool $waitOnMinutelyRateLimitHit) + public function setWaitOnMinutelyRateLimitHit(bool $waitOnMinutelyRateLimitHit): void { $this->waitOnMinutelyRateLimitHit = $waitOnMinutelyRateLimitHit; }