From 836738f59c425ff0289c78070332f9de1c4d8465 Mon Sep 17 00:00:00 2001 From: Gustavo Meyer Date: Fri, 26 Aug 2022 13:07:38 -0700 Subject: [PATCH 1/5] DTSERWONE-1083 - Add PHPStan to perform static analysis and prevent PHP version issues --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 194cde21..52aca364 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,44 @@ on: - bugfix/** jobs: + static-analisis: + name: Static-analysis + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ 'ubuntu-latest' ] + # The 5.6 PHP will be validated by 7.0 since the Static analysis tools is only supported by 7.x and latest + php-versions: [ '7.0','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 runs-on: ${{ matrix.operating-system }} @@ -28,6 +66,7 @@ jobs: steps: - uses: actions/checkout@master + #sets up the PHP version - name: Setup PHP uses: shivammathur/setup-php@v2 with: From 9f39aad5485818e5fbdb9edbbda7ce82684ea4c6 Mon Sep 17 00:00:00 2001 From: Gustavo Meyer Date: Fri, 26 Aug 2022 13:09:41 -0700 Subject: [PATCH 2/5] DTSERWONE-1083 - Address PHP-8.1 issues --- src/Hyperwallet/Response/ErrorResponse.php | 23 ++++++++++++++-- src/Hyperwallet/Response/ListResponse.php | 26 ++++++++++++++++--- tests/Hyperwallet/Tests/HyperwalletTest.php | 4 ++- .../Tests/Model/ClientTokenTest.php | 2 +- 4 files changed, 48 insertions(+), 7 deletions(-) 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/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 @@ Date: Fri, 26 Aug 2022 13:17:12 -0700 Subject: [PATCH 3/5] DTSERWONE-1083 - Fix documentation errors and Access to an undefined property for businessName --- src/Hyperwallet/Model/BusinessStakeholder.php | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) 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) { From 2a676c2b587216ee56383221c7458ff85a0937aa Mon Sep 17 00:00:00 2001 From: Gustavo Meyer Date: Fri, 26 Aug 2022 13:20:03 -0700 Subject: [PATCH 4/5] DTSERWONE-1083 - Remove 7.0 from static analyses due dev tool dependencies --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52aca364..0bcc4bb4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,7 @@ jobs: fail-fast: false matrix: operating-system: [ 'ubuntu-latest' ] - # The 5.6 PHP will be validated by 7.0 since the Static analysis tools is only supported by 7.x and latest - php-versions: [ '7.0','7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ] + php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ] steps: - uses: actions/checkout@master @@ -52,7 +51,7 @@ jobs: #evaluate the code - name: Run static analysis tool run: | - vendor/bin/phpstan analyse -l 1 src/Hyperwallet tests + vendor/bin/phpstan analyse src/Hyperwallet tests tests: name: Tests From 8297dd3106698b3f4782ada0adcea914389794e1 Mon Sep 17 00:00:00 2001 From: Gustavo Meyer Date: Fri, 26 Aug 2022 13:23:19 -0700 Subject: [PATCH 5/5] DTSERWONE-1083 - Chain CI steps --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bcc4bb4..80785e93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ on: - bugfix/** jobs: - static-analisis: + static-analysis: name: Static-analysis runs-on: ${{ matrix.operating-system }} strategy: @@ -55,6 +55,7 @@ jobs: tests: name: Tests + needs: [static-analysis] runs-on: ${{ matrix.operating-system }} strategy: fail-fast: false @@ -85,6 +86,7 @@ jobs: code-coverage: name: Report code coverage + needs: [tests] runs-on: ${{ matrix.operating-system }} strategy: fail-fast: false