From 0772208e67d6ee4a6d2dde220f1f69a1f10e9a78 Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Wed, 15 Dec 2021 18:10:12 +0300 Subject: [PATCH 1/2] review + cs fix --- src/Http/Client.php | 6 ++---- src/Resources/Companies.php | 4 ++-- src/Resources/Files.php | 2 +- src/helpers.php | 11 +++-------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Http/Client.php b/src/Http/Client.php index f4a45ff2..ff3a58da 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -53,7 +53,7 @@ class Client * @param array $clientOptions options to be passed to Guzzle upon each request * @param bool $wrapResponse wrap request response in own Response object */ - public function __construct($config = [], $client = null, $clientOptions = [], $wrapResponse = true) + public function __construct(array $config = [], $client = null, array $clientOptions = [], bool $wrapResponse = true) { $this->clientOptions = $clientOptions; $this->wrapResponse = $wrapResponse; @@ -152,10 +152,8 @@ protected function generateUrl($endpoint, $query_string = null, $requires_auth = /** * @param string $query_string the query string to send to the endpoint * @param string $addition addition query string to send to the endpoint - * - * @return string */ - protected function addQuery($query_string, $addition) + protected function addQuery($query_string, $addition): string { $result = ''; diff --git a/src/Resources/Companies.php b/src/Resources/Companies.php index 695dd239..0b01c814 100644 --- a/src/Resources/Companies.php +++ b/src/Resources/Companies.php @@ -175,8 +175,8 @@ public function searchByDomain( /** * Returns a company with id $id. * - * @param int $id - * @param array $params Array of optional parameters ['includeMergeAudits', 'includePropertyVersions'] + * @param int $id + * @param array $params Array of optional parameters ['includeMergeAudits', 'includePropertyVersions'] * * @see https://developers.hubspot.com/docs/methods/companies/get_company * diff --git a/src/Resources/Files.php b/src/Resources/Files.php index cec25e26..b268d2f6 100644 --- a/src/Resources/Files.php +++ b/src/Resources/Files.php @@ -277,7 +277,7 @@ protected function getAdditionalParams(array $params): array protected function getDefaultOptions(): array { return [ - 'access' => 'PUBLIC_INDEXABLE' + 'access' => 'PUBLIC_INDEXABLE', ]; } } diff --git a/src/helpers.php b/src/helpers.php index 006b33c9..c549e374 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -4,12 +4,9 @@ /** * Generate a query string. * - * @param array $params - * @param int $encoding - * - * @return string + * @param int $encoding */ - function build_query_string($params = [], $encoding = PHP_QUERY_RFC3986) + function build_query_string(array $params = [], $encoding = PHP_QUERY_RFC3986): string { if (empty($params)) { return ''; @@ -43,10 +40,8 @@ function build_query_string($params = [], $encoding = PHP_QUERY_RFC3986) * @param string $key the name of the query variable * @param array $items an array of item values for the variable * @param int $encoding - * - * @return string */ - function build_batch_query_string($key, $items, $encoding = PHP_QUERY_RFC3986) + function build_batch_query_string($key, array $items, $encoding = PHP_QUERY_RFC3986): string { return array_reduce($items, function ($query, $item) use ($key, $encoding) { return $query.'&'.url_encode($key, $encoding).'='.url_encode($item, $encoding); From cd144546f9b318679aa2b8366552e7ec44527c17 Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Fri, 17 Dec 2021 14:47:49 +0300 Subject: [PATCH 2/2] type hiunting --- src/Factory.php | 2 +- src/Http/Client.php | 4 ++-- src/Utils/OAuth2.php | 4 +--- src/Utils/Webhooks.php | 4 +--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Factory.php b/src/Factory.php index e93d8d0f..bd3e5b53 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -62,7 +62,7 @@ class Factory * @param array $clientOptions options to be send with each request * @param bool $wrapResponse wrap request response in own Response object */ - public function __construct(array $config = [], Client $client = null, array $clientOptions = [], $wrapResponse = true) + public function __construct(array $config = [], Client $client = null, array $clientOptions = [], bool $wrapResponse = true) { if (is_null($client)) { $client = new Client($config, null, $clientOptions, $wrapResponse); diff --git a/src/Http/Client.php b/src/Http/Client.php index ff3a58da..ec733a61 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -90,7 +90,7 @@ public function __construct(array $config = [], $client = null, array $clientOpt * * @return ResponseInterface|\SevenShores\Hubspot\Http\Response */ - public function request($method, $endpoint, array $options = [], $query_string = null, $requires_auth = true) + public function request(string $method, string $endpoint, array $options = [], $query_string = null, bool $requires_auth = true) { if ($requires_auth && empty($this->key)) { throw new InvalidArgument('You must provide a Hubspot api key or token.'); @@ -127,7 +127,7 @@ public function request($method, $endpoint, array $options = [], $query_string = * * @return string */ - protected function generateUrl($endpoint, $query_string = null, $requires_auth = true) + protected function generateUrl(string $endpoint, $query_string = null, $requires_auth = true) { $url = $endpoint.'?'; diff --git a/src/Utils/OAuth2.php b/src/Utils/OAuth2.php index 78c7a214..85ee08a4 100644 --- a/src/Utils/OAuth2.php +++ b/src/Utils/OAuth2.php @@ -13,10 +13,8 @@ class OAuth2 * @param string $redirectURI The URL that you want the visitor redirected to after granting access to your app. For security reasons, this URL must use https. * @param array $scopesArray a set of scopes that your app will need access to * @param array $optionalScopesArray a set of optional scopes that your app will need access to - * - * @return string */ - public static function getAuthUrl($clientId, $redirectURI, array $scopesArray = [], array $optionalScopesArray = []) + public static function getAuthUrl($clientId, $redirectURI, array $scopesArray = [], array $optionalScopesArray = []): string { return self::AUTHORIZE_URL.'?'.http_build_query([ 'client_id' => $clientId, diff --git a/src/Utils/Webhooks.php b/src/Utils/Webhooks.php index 08353f58..932c1a1a 100644 --- a/src/Utils/Webhooks.php +++ b/src/Utils/Webhooks.php @@ -10,10 +10,8 @@ class Webhooks * @param string $signature hubspot signarute * @param string $secret the Secret of your app * @param string $requestBody a set of scopes that your app will need access to - * - * @return bool */ - public static function isHubspotSignatureValid($signature, $secret, $requestBody) + public static function isHubspotSignatureValid($signature, $secret, $requestBody): bool { return $signature == hash('sha256', $secret.$requestBody); }