From d4b08bd90a58a90bb82df3b3084136e92f6da015 Mon Sep 17 00:00:00 2001 From: Gustavo Meyer <107439697+grmeyer-hw-dev@users.noreply.github.com> Date: Thu, 10 Nov 2022 13:12:02 -0800 Subject: [PATCH] [Investigation] [WIP] [Part-2] feature/DTSERWONE-1083 - PHP 8.1 - Address Documentation issue (#120) * DTSERWONE-1083 - Add PHPStan to perform static analysis and prevent PHP version issues * DTSERWONE-1083 - Address PHP-8.1 issues * DTSERWONE-1083 - Fix documentation errors and Access to an undefined property for businessName * DTSERWONE-1083 - Remove 7.0 from static analyses due dev tool dependencies * DTSERWONE-1083 - Chain CI steps * DTSERWONE-1083 - Address documentation issue and missing references pointed by PHPStan level 2 * DTSERWONE-1083 - Bump up PHPStan level 1 --- .github/workflows/ci.yml | 40 ++++++++++++++++++ .../Exception/HyperwalletApiException.php | 7 ++-- src/Hyperwallet/Hyperwallet.php | 42 ++++++++++++------- src/Hyperwallet/Model/BaseModel.php | 10 ++--- src/Hyperwallet/Model/BusinessStakeholder.php | 30 +++++++------ src/Hyperwallet/Model/PrepaidCard.php | 4 +- src/Hyperwallet/Model/TransferRefund.php | 8 ++-- src/Hyperwallet/Response/ErrorResponse.php | 23 +++++++++- src/Hyperwallet/Response/ListResponse.php | 26 ++++++++++-- src/Hyperwallet/Util/ApiClient.php | 3 +- .../Util/HyperwalletEncryption.php | 6 +-- tests/Hyperwallet/Tests/HyperwalletTest.php | 4 +- .../Tests/Model/ClientTokenTest.php | 2 +- 13 files changed, 151 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 194cde21..75626ce4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,8 +16,46 @@ on: - bugfix/** jobs: + static-analysis: + name: Static-analysis + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ 'ubuntu-latest' ] + php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ] + + steps: + - uses: actions/checkout@master + + #sets up the PHP version + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: xdebug + + #validate composer files + - name: Validate composer.json and composer.lock + run: composer validate + + #get dependencies + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + #get static analysis tool + - name: Install static analysis tool + run: | + composer require --dev phpstan/phpstan + + #evaluate the code + - name: Run static analysis tool + run: | + vendor/bin/phpstan analyse -l 1 src/Hyperwallet tests + tests: name: Tests + needs: [static-analysis] runs-on: ${{ matrix.operating-system }} strategy: fail-fast: false @@ -28,6 +66,7 @@ jobs: steps: - uses: actions/checkout@master + #sets up the PHP version - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -47,6 +86,7 @@ jobs: code-coverage: name: Report code coverage + needs: [tests] runs-on: ${{ matrix.operating-system }} strategy: fail-fast: false diff --git a/src/Hyperwallet/Exception/HyperwalletApiException.php b/src/Hyperwallet/Exception/HyperwalletApiException.php index 6ae1f24b..06e36b0e 100644 --- a/src/Hyperwallet/Exception/HyperwalletApiException.php +++ b/src/Hyperwallet/Exception/HyperwalletApiException.php @@ -1,5 +1,6 @@ getMessage(); parent::__construct($message, 0, $previous); diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index 612602e9..3f800226 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -70,7 +70,7 @@ class Hyperwallet { * @param string $password The API password * @param string|null $programToken The program token that is used for some API calls * @param string $server The API server to connect to - * @param string $encryptionData Encryption data to initialize ApiClient with encryption enabled + * @param array $encryptionData Encryption data to initialize ApiClient with encryption enabled * @param array $clientOptions Guzzle Client Options * * @throws HyperwalletArgumentException @@ -1467,9 +1467,9 @@ public function createBankCardStatusTransition($userToken, $bankCardToken, BankC /** * Get a bank card status transition * - * @param $userToken The user token - * @param $bankCardToken The bank card token - * @param $statusTransitionToken The status transition token + * @param string $userToken The user token + * @param string $bankCardToken The bank card token + * @param string $statusTransitionToken The status transition token * @return BankCardStatusTransition * * @throws HyperwalletApiException @@ -2150,7 +2150,9 @@ public function createUserStatusTransition($userToken, UserStatusTransition $tra * Activate a User * * @param string $userToken The user token - * @return UserStatusTransition + * @return UserStatusTransition the status transition + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException */ public function activateUser($userToken) { $transition = new UserStatusTransition(); @@ -2162,7 +2164,9 @@ public function activateUser($userToken) { * De-activate a User * * @param string $userToken The user token - * @return UserStatusTransition + * @return UserStatusTransition the status transition + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException */ public function deactivateUser($userToken) { $transition = new UserStatusTransition(); @@ -2173,8 +2177,10 @@ public function deactivateUser($userToken) { /** * Lock a User account * - * @param userToken User token - * @return The status transition + * @param string $userToken User token + * @return UserStatusTransition the status transition + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException */ public function lockUser($userToken) { $transition = new UserStatusTransition(); @@ -2185,8 +2191,10 @@ public function lockUser($userToken) { /** * Freeze a User account * - * @param userToken User token - * @return The status transition + * @param string $userToken User token + * @return UserStatusTransition the status transition + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException */ public function freezeUser($userToken) { $transition = new UserStatusTransition(); @@ -2197,8 +2205,10 @@ public function freezeUser($userToken) { /** * Pre-activate a User account * - * @param userToken User token - * @return The status transition + * @param string $userToken User token + * @return UserStatusTransition the status transition + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException */ public function preactivateUser($userToken) { $transition = new UserStatusTransition(); @@ -2489,12 +2499,14 @@ public function uploadDocumentsForBusinessStakeholder($userToken, $businessToken /** * Create a Business Stakeholder * - * @param Business Stakeholder $BusinessStakeholder The Business Stakeholder data + * @param string $userToken The user token + * @param BusinessStakeholder $businessStakeholder The business stakeholder * @return BusinessStakeholder * + * @throws HyperwalletArgumentException * @throws HyperwalletApiException */ - public function createBusinessStakeholder($userToken,$businessStakeholder) { + public function createBusinessStakeholder($userToken, $businessStakeholder) { if (empty($userToken)) { throw new HyperwalletArgumentException('userToken is required!'); } @@ -2505,9 +2517,7 @@ public function createBusinessStakeholder($userToken,$businessStakeholder) { /** * Update a Business Stakeholder * - * @param Business Stakeholder $BusinessStakeholder The Business Stakeholder * @return BusinessStakeholder - * * @throws HyperwalletArgumentException * @throws HyperwalletApiException diff --git a/src/Hyperwallet/Model/BaseModel.php b/src/Hyperwallet/Model/BaseModel.php index 28c97675..6037a30a 100644 --- a/src/Hyperwallet/Model/BaseModel.php +++ b/src/Hyperwallet/Model/BaseModel.php @@ -53,7 +53,7 @@ public function __construct(array $readOnlyProperties = array(), array $properti * * Magic get method * - * @param $key + * @param string $key * @return mixed */ public function __get($key) { @@ -68,8 +68,8 @@ public function __get($key) { * * Magic set method * - * @param $key - * @param $value + * @param string $key + * @param mixed $value */ public function __set($key, $value) { if (!in_array($key, $this->updatedProperties)) { @@ -84,7 +84,7 @@ public function __set($key, $value) { * * Magic isset method * - * @param $key + * @param string $key * @return bool * * @access private @@ -98,7 +98,7 @@ public function __isset($key) { * * Magic unset method * - * @param $key + * @param string $key */ public function __unset($key) { unset($this->updatedProperties[array_search($key, $this->updatedProperties)]); diff --git a/src/Hyperwallet/Model/BusinessStakeholder.php b/src/Hyperwallet/Model/BusinessStakeholder.php index 518aaa54..83c2fb2b 100644 --- a/src/Hyperwallet/Model/BusinessStakeholder.php +++ b/src/Hyperwallet/Model/BusinessStakeholder.php @@ -5,10 +5,10 @@ * Represents a V4 BusinessStakeholder * * @property string $token The BusinessStakeholder token - * @property boolen $isBusinessContact The business contact - * @property boolen $isDirector The Director - * @property boolen $isUltimateBeneficialOwner The UltimateBeneficial Owner - * @property boolen $isSeniorManagingOfficial The Senior Managing Official + * @property bool $isBusinessContact The business contact + * @property bool $isDirector The Director + * @property bool $isUltimateBeneficialOwner The UltimateBeneficial Owner + * @property bool $isSeniorManagingOfficial The Senior Managing Official * @property string $verificationStatus The status of Business user verification * @property string $status The Business user status * @property \DateTime $createdOn The Business user creation date @@ -65,6 +65,10 @@ class BusinessStakeholder extends BaseModel { const GOVERNMENT_ID_TYPE_PASSPORT = 'PASSPORT'; const GOVERNMENT_ID_TYPE_NATIONAL_ID_CARD = 'NATIONAL_ID_CARD'; + /** + * @var mixed|null + */ + private $businessName; public static function FILTERS_ARRAY() { return array('status', 'createdBefore', 'createdAfter', 'sortBy', 'limit'); @@ -102,7 +106,7 @@ public function setToken($token) { /** * Get the BusinessStakeholder Contact * - * @return Boolean + * @return bool */ public function getIsBusinessContact() { return $this->isBusinessContact; @@ -110,7 +114,7 @@ public function getIsBusinessContact() { /** * Set the BusinessStakeholder Contact * - * @param Boolean $isBusinessContact + * @param bool $isBusinessContact * @return BusinessStakeholder */ @@ -122,7 +126,7 @@ public function setIsBusinessContact($isBusinessContact) { /** * Get the BusinessStakeholder Director * - * @return Boolean + * @return bool */ public function getIsDirector() { return $this->isDirector; @@ -131,7 +135,7 @@ public function getIsDirector() { /** * Set the BusinessStakeholder Director * - * @param Boolean $isDirector + * @param bool $isDirector * @return BusinessStakeholder */ @@ -143,7 +147,7 @@ public function setIsDirector($isDirector) { /** * Get the BusinessStakeholder Ultimate Beneficial Owner * - * @return Boolean + * @return bool */ public function getIsUltimateBeneficialOwner() { return $this->isUltimateBeneficialOwner; @@ -152,7 +156,7 @@ public function getIsUltimateBeneficialOwner() { /** * Set the BusinessStakeholder Ultimate Beneficial Owner * - * @param Boolean $isUltimateBeneficialOwner + * @param bool $isUltimateBeneficialOwner * @return BusinessStakeholder */ @@ -164,7 +168,7 @@ public function setIsUltimateBeneficialOwner($isUltimateBeneficialOwner) { /** * Get the BusinessStakeholder Senior Managing Official * - * @return Boolean + * @return bool */ public function getIsSeniorManagingOfficial() { return $this->isSeniorManagingOfficial; @@ -173,7 +177,7 @@ public function getIsSeniorManagingOfficial() { /** * Set the BusinessStakeholder Senior Managing Official * - * @param Boolean $isSeniorManagingOfficial + * @param bool $isSeniorManagingOfficial * @return BusinessStakeholder */ @@ -482,7 +486,7 @@ public function getGovernmentIdType() { /** * Set the business governmentIdType * - * @param string $businessType + * @param string $governmentIdType * @return BusinessStakeholder */ public function setGovernmentIdType($governmentIdType) { diff --git a/src/Hyperwallet/Model/PrepaidCard.php b/src/Hyperwallet/Model/PrepaidCard.php index 524bb9a0..d71b5902 100644 --- a/src/Hyperwallet/Model/PrepaidCard.php +++ b/src/Hyperwallet/Model/PrepaidCard.php @@ -217,7 +217,7 @@ public function getReplacementOf() { /** * Set the prepaid card token to be replaced * - * @param string $token + * @param string $replacementOf * @return PrepaidCard */ public function setReplacementOf($replacementOf) { @@ -237,7 +237,7 @@ public function getReplacementReason() { /** * set the prepaid card's replacement reason * - * @param string $token + * @param string $replacementReason * @return PrepaidCard */ public function setReplacementReason($replacementReason) { diff --git a/src/Hyperwallet/Model/TransferRefund.php b/src/Hyperwallet/Model/TransferRefund.php index 89ec9780..d3de96cf 100644 --- a/src/Hyperwallet/Model/TransferRefund.php +++ b/src/Hyperwallet/Model/TransferRefund.php @@ -89,7 +89,7 @@ public function getClientRefundId() { /** * Set the transfer token * - * @param string $token + * @param string $clientRefundId * @return TransferRefund */ public function setClientRefundId($clientRefundId) { @@ -298,7 +298,7 @@ public function setMemo($memo) { } /** - * Get transfer memo + * Get the Foreign Exchanges * * @return string */ @@ -307,9 +307,9 @@ public function getForeignExchanges() { } /** - * Set transfer memo + * Set the Foreign Exchanges * - * @param string $memo + * @param string $foreignExchanges * @return TransferRefund */ public function setForeignExchanges($foreignExchanges) { diff --git a/src/Hyperwallet/Response/ErrorResponse.php b/src/Hyperwallet/Response/ErrorResponse.php index 67555df3..2579651c 100644 --- a/src/Hyperwallet/Response/ErrorResponse.php +++ b/src/Hyperwallet/Response/ErrorResponse.php @@ -40,7 +40,7 @@ class ErrorResponse implements \Countable, \ArrayAccess { public function __construct($statusCode, array $errors) { $this->statusCode = $statusCode; $this->errors = array_map(function ($error) { - if (!isset($relatedResources) && isset($error['relatedResources'])) { + if (!isset($this->relatedResources) && isset($error['relatedResources'])) { $this->relatedResources = $error['relatedResources']; } return new Error($error); @@ -84,7 +84,11 @@ public function getRelatedResources() { *

* The return value is cast to an integer. * @since 5.1.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function count() { return count($this->errors); } @@ -102,7 +106,11 @@ public function count() { *

* The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->errors[$offset]); } @@ -117,7 +125,11 @@ public function offsetExists($offset) { *

* @return mixed Can return all value types. * @since 5.0.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->errors[$offset]; } @@ -135,7 +147,11 @@ public function offsetGet($offset) { *

* @return void * @since 5.0.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->errors[$offset] = $value; } @@ -150,9 +166,12 @@ public function offsetSet($offset, $value) { *

* @return void * @since 5.0.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->errors[$offset]); } - } \ No newline at end of file diff --git a/src/Hyperwallet/Response/ListResponse.php b/src/Hyperwallet/Response/ListResponse.php index 2c1b9076..8420e2ee 100644 --- a/src/Hyperwallet/Response/ListResponse.php +++ b/src/Hyperwallet/Response/ListResponse.php @@ -87,7 +87,7 @@ public function getData() { /** * Get the Total number of Model's * - * @var int + * @return int */ public function getLimit() { return $this->limit; @@ -96,7 +96,7 @@ public function getLimit() { /** * Get Has Next Page of Model's * - * @var boolean + * @return boolean */ public function getHasNextPage() { return $this->hasNextPage; @@ -105,7 +105,7 @@ public function getHasNextPage() { /** * Get Has Previous Page of Model's * - * @var boolean + * @return boolean */ public function getHasPreviousPage() { return $this->hasPreviousPage; @@ -122,7 +122,11 @@ public function getHasPreviousPage() { *

* The return value is cast to an integer. * @since 5.1.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function count() { return count($this->data); } @@ -139,7 +143,11 @@ public function count() { *

* The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->data[$offset]); } @@ -154,7 +162,11 @@ public function offsetExists($offset) { *

* @return mixed Can return all value types. * @since 5.0.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->data[$offset]; } @@ -172,7 +184,11 @@ public function offsetGet($offset) { *

* @return void * @since 5.0.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->data[$offset] = $value; } @@ -187,7 +203,11 @@ public function offsetSet($offset, $value) { *

* @return void * @since 5.0.0 + * + * Note: Temporarily suppress the required return type, to keep compatibility with PHP 5.6 + * the #[\ReturnTypeWillChange] must be removed once 5.6 */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->data[$offset]); } diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index aecad93f..f51327dd 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -7,6 +7,7 @@ use Hyperwallet\Exception\HyperwalletException; use Hyperwallet\Model\BaseModel; use Hyperwallet\Response\ErrorResponse; +use Psr\Http\Message\ResponseInterface; /** * The internal API client @@ -198,7 +199,7 @@ private function doRequest($method, $url, array $urlParams, array $options) { /** * Checks whether Content-Type header is valid in response * - * @param string $response Response to be checked + * @param ResponseInterface $response Response to be checked * * @throws HyperwalletException */ diff --git a/src/Hyperwallet/Util/HyperwalletEncryption.php b/src/Hyperwallet/Util/HyperwalletEncryption.php index 3cc5cbe6..6f6896fe 100644 --- a/src/Hyperwallet/Util/HyperwalletEncryption.php +++ b/src/Hyperwallet/Util/HyperwalletEncryption.php @@ -87,9 +87,9 @@ class HyperwalletEncryption { * @param string $clientPrivateKeySetLocation String that can be a URL or path to file with client JWK set * @param string $hyperwalletKeySetLocation String that can be a URL or path to file with hyperwallet JWK set * @param string $encryptionAlgorithm JWE encryption algorithm, by default value = RSA-OAEP-256 - * @param array $signAlgorithm JWS signature algorithm, by default value = RS256 - * @param array $encryptionMethod JWE encryption method, by default value = A256CBC-HS512 - * @param array $jwsExpirationMinutes Minutes when JWS signature is valid, by default value = 5 + * @param string $signAlgorithm JWS signature algorithm, by default value = RS256 + * @param string $encryptionMethod JWE encryption method, by default value = A256CBC-HS512 + * @param integer $jwsExpirationMinutes Minutes when JWS signature is valid, by default value = 5 */ public function __construct($clientPrivateKeySetLocation, $hyperwalletKeySetLocation, $encryptionAlgorithm = 'RSA-OAEP-256', $signAlgorithm = 'RS256', $encryptionMethod = 'A256CBC-HS512', diff --git a/tests/Hyperwallet/Tests/HyperwalletTest.php b/tests/Hyperwallet/Tests/HyperwalletTest.php index 0457e065..81f0fd3a 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -705,7 +705,7 @@ public function testListPaperChecks_noParameters() { $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); $apiClientMock = $this->createAndInjectApiClientMock($client); - \Phake::when($apiClientMock)->doGet('/rest/v4/users/{user-token}/paper-checks', array('user-token' => 'test-user-token'), array())->thenReturn(array('limit' => 1,'limit' => 1,'hasNextPage' => false ,'hasPreviousPage' => false,'links' => 'links', 'data' => array())); + \Phake::when($apiClientMock)->doGet('/rest/v4/users/{user-token}/paper-checks', array('user-token' => 'test-user-token'), array())->thenReturn(array('limit' => 1,'hasNextPage' => false ,'hasPreviousPage' => false,'links' => 'links', 'data' => array())); // Run test $paperCheckList = $client->listPaperChecks('test-user-token'); @@ -4233,6 +4233,7 @@ public function testUpdateVerificationStatus_allParameters() { \Phake::when($apiClientMock)->doPut('/rest/v4/users/{user-token}', array('user-token' => 'test-user-token'), $user, array())->thenReturn(array("status"=> User::STATUS_PRE_ACTIVATED, 'verificationStatus'=> User::VERIFICATION_STATUS_REQUIRED)); \Phake::when($apiClientMock)->doGet('/rest/v4/users/{user-token}', array('user-token' => 'test-user-token'), array())->thenReturn(array("status"=> User::STATUS_PRE_ACTIVATED, 'verificationStatus'=> User::VERIFICATION_STATUS_REQUIRED)); + $responseUser = null; // Run test try { $responseUser = $client->updateVerificationStatus('test-user-token', User::VERIFICATION_STATUS_REQUESTED); @@ -5112,6 +5113,7 @@ public function testGetTransferRefund_successful() { $uriParams, $queryParams)->thenReturn(array('token' => $refundToken)); // Run test + $transferRefund = null; try { $transferRefund = $client->getTransferRefund($transferToken, $refundToken); } catch (HyperwalletArgumentException $e) { diff --git a/tests/Hyperwallet/Tests/Model/ClientTokenTest.php b/tests/Hyperwallet/Tests/Model/ClientTokenTest.php index 640c2752..d17e4d7d 100644 --- a/tests/Hyperwallet/Tests/Model/ClientTokenTest.php +++ b/tests/Hyperwallet/Tests/Model/ClientTokenTest.php @@ -1,7 +1,7 @@