From 67332e1f703e43f99cba3d9388cde99a17cdc151 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:13:27 +0200 Subject: [PATCH 01/14] Add missing abstract function declaration --- src/PaytrailClient.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/PaytrailClient.php b/src/PaytrailClient.php index 78c10fc..37471ae 100644 --- a/src/PaytrailClient.php +++ b/src/PaytrailClient.php @@ -44,6 +44,18 @@ protected function createHttpClient() $this->http_client = new RequestClient(); } + /** + * A proxy for the Signature class' static method + * to be used via a client instance. + * + * @param array $response The response parameters. + * @param string $body The response body. + * @param string $signature The response signature key. + * + * @throws HmacException + */ + abstract public function validateHmac(array $response = [], string $body = '', string $signature = ''); + /** * A wrapper for post requests. * From 2f4c03f68d626f90449a6d523eb6e6b9a3ba022a Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:18:50 +0200 Subject: [PATCH 02/14] Fix invalid @param annotations --- src/Interfaces/ItemInterface.php | 4 ++-- src/Util/Signature.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Interfaces/ItemInterface.php b/src/Interfaces/ItemInterface.php index b25a202..7f8a031 100644 --- a/src/Interfaces/ItemInterface.php +++ b/src/Interfaces/ItemInterface.php @@ -36,7 +36,7 @@ public function getUnitPrice(): ?int; /** * Set the unit price. * - * @param int/null $unitPrice + * @param int|null $unitPrice * @return ItemInterface Return self to enable chaining. */ public function setUnitPrice(?int $unitPrice): ItemInterface; @@ -51,7 +51,7 @@ public function getUnits(): ?int; /** * Set the units. * - * @param int/null $units + * @param int|null $units * @return ItemInterface Return self to enable chaining. */ public function setUnits(?int $units): ItemInterface; diff --git a/src/Util/Signature.php b/src/Util/Signature.php index f91504a..f34e578 100644 --- a/src/Util/Signature.php +++ b/src/Util/Signature.php @@ -26,10 +26,10 @@ class Signature * @see https://paytrail.github.io/api-documentation/#/?id=headers-and-request-signing * @see https://paytrail.github.io/api-documentation/#/?id=redirect-and-callback-url-parameters * - * @param array[string] $params HTTP headers in an associative array. - * + * @param array $params HTTP headers in an associative array. * @param string $body HTTP request body, empty string for GET requests * @param string $secretKey The merchant secret key. + * * @return string SHA-256 HMAC */ public static function calculateHmac(array $params = [], string $body = '', string $secretKey = '') From 912b0b3a662bb4e914db5798c4a415aa15b05db2 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:19:01 +0200 Subject: [PATCH 03/14] Fix wrong @return annotation --- src/Model/Commission.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Model/Commission.php b/src/Model/Commission.php index d545787..b03bdc1 100644 --- a/src/Model/Commission.php +++ b/src/Model/Commission.php @@ -89,8 +89,6 @@ public function setAmount(int $amount): Commission /** * The getter for the amount. - * - * @return string */ public function getAmount(): int { From d5b6dbfc52074365e048867e50d1a7fd95395ba5 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:21:49 +0200 Subject: [PATCH 04/14] Remove useless inherited variable declaration --- src/Exception/ValidationException.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Exception/ValidationException.php b/src/Exception/ValidationException.php index fd29973..9d720b8 100644 --- a/src/Exception/ValidationException.php +++ b/src/Exception/ValidationException.php @@ -19,13 +19,6 @@ */ class ValidationException extends \Exception { - /** - * Holds the previous NestedValidationException instance. - * - * $var NestedValidationException - */ - protected $previous; - /** * Holds all error messages. * From 8e11773b0a4339e99b767b7307a1a266d0ca05fb Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:23:30 +0200 Subject: [PATCH 05/14] Remove references to Respect\Validation --- src/Exception/ValidationException.php | 2 -- src/Interfaces/AddressInterface.php | 2 +- src/Interfaces/CallbackUrlInterface.php | 2 +- src/Interfaces/CommissionInterface.php | 2 +- src/Interfaces/CustomerInterface.php | 2 +- src/Interfaces/ItemInterface.php | 2 +- src/Interfaces/PaymentRequestInterface.php | 2 +- src/Model/Address.php | 2 +- src/Model/CallbackUrl.php | 2 +- src/Model/Item.php | 4 ++-- src/Model/RefundItem.php | 2 +- src/Model/Token/Customer.php | 2 +- src/Request/AbstractPaymentRequest.php | 2 +- src/Request/AddCardFormRequest.php | 2 +- src/Request/CitPaymentRequest.php | 2 +- src/Request/EmailRefundRequest.php | 3 +-- src/Request/GetTokenRequest.php | 2 +- src/Request/MitPaymentRequest.php | 2 +- src/Request/PaymentStatusRequest.php | 2 +- src/Request/RefundRequest.php | 2 +- src/Request/RevertPaymentAuthHoldRequest.php | 2 +- src/Request/ShopInShopPaymentRequest.php | 2 +- 22 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/Exception/ValidationException.php b/src/Exception/ValidationException.php index 9d720b8..0fe0e9d 100644 --- a/src/Exception/ValidationException.php +++ b/src/Exception/ValidationException.php @@ -10,8 +10,6 @@ /** * Class ValidationException - * This exception is a simple wrapper for - * a Respect\Validation NestedValidationException instance. * * This exception holds the general expection message * diff --git a/src/Interfaces/AddressInterface.php b/src/Interfaces/AddressInterface.php index 7f8c5b5..7091983 100644 --- a/src/Interfaces/AddressInterface.php +++ b/src/Interfaces/AddressInterface.php @@ -20,7 +20,7 @@ interface AddressInterface { /** - * Validates with Respect\Validation library and throws exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/CallbackUrlInterface.php b/src/Interfaces/CallbackUrlInterface.php index d8ef323..e3a5806 100644 --- a/src/Interfaces/CallbackUrlInterface.php +++ b/src/Interfaces/CallbackUrlInterface.php @@ -20,7 +20,7 @@ interface CallbackUrlInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/CommissionInterface.php b/src/Interfaces/CommissionInterface.php index c1ccff2..1a28716 100644 --- a/src/Interfaces/CommissionInterface.php +++ b/src/Interfaces/CommissionInterface.php @@ -21,7 +21,7 @@ interface CommissionInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/CustomerInterface.php b/src/Interfaces/CustomerInterface.php index b501f83..ea5c7b6 100644 --- a/src/Interfaces/CustomerInterface.php +++ b/src/Interfaces/CustomerInterface.php @@ -20,7 +20,7 @@ interface CustomerInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/ItemInterface.php b/src/Interfaces/ItemInterface.php index 7f8a031..25b3a61 100644 --- a/src/Interfaces/ItemInterface.php +++ b/src/Interfaces/ItemInterface.php @@ -20,7 +20,7 @@ interface ItemInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/PaymentRequestInterface.php b/src/Interfaces/PaymentRequestInterface.php index 16dfea1..b4ab3f0 100644 --- a/src/Interfaces/PaymentRequestInterface.php +++ b/src/Interfaces/PaymentRequestInterface.php @@ -20,7 +20,7 @@ interface PaymentRequestInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/Address.php b/src/Model/Address.php index 289e6d4..6fcb9c3 100644 --- a/src/Model/Address.php +++ b/src/Model/Address.php @@ -25,7 +25,7 @@ class Address implements \JsonSerializable, AddressInterface use JsonSerializable; /** - * Validates with Respect\Validation library and throws exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/CallbackUrl.php b/src/Model/CallbackUrl.php index 8dc92da..480ba67 100644 --- a/src/Model/CallbackUrl.php +++ b/src/Model/CallbackUrl.php @@ -25,7 +25,7 @@ class CallbackUrl implements \JsonSerializable, CallbackUrlInterface use JsonSerializable; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/Item.php b/src/Model/Item.php index 3b05553..8e870c4 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -363,7 +363,7 @@ public function setCommission(?CommissionInterface $commission): ItemInterface } /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ @@ -393,7 +393,7 @@ public function validate() } /** - * Validates shop-in-shop props with Respect\Validation library and throws an exception for invalid objects + * Validates shop-in-shop props and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/RefundItem.php b/src/Model/RefundItem.php index 10b5ca3..88f4473 100644 --- a/src/Model/RefundItem.php +++ b/src/Model/RefundItem.php @@ -23,7 +23,7 @@ class RefundItem implements \JsonSerializable use JsonSerializable; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/Token/Customer.php b/src/Model/Token/Customer.php index 80580d5..fb0033f 100644 --- a/src/Model/Token/Customer.php +++ b/src/Model/Token/Customer.php @@ -22,7 +22,7 @@ class Customer implements \JsonSerializable use ObjectPropertyConverter; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index 581a4fa..b952b0e 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -32,7 +32,7 @@ abstract class AbstractPaymentRequest implements \JsonSerializable, PaymentReque use JsonSerializable; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/AddCardFormRequest.php b/src/Request/AddCardFormRequest.php index 03a5dff..98fd7a5 100644 --- a/src/Request/AddCardFormRequest.php +++ b/src/Request/AddCardFormRequest.php @@ -52,7 +52,7 @@ class AddCardFormRequest implements \JsonSerializable protected $signature; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/CitPaymentRequest.php b/src/Request/CitPaymentRequest.php index 8a9f9c0..2ead458 100644 --- a/src/Request/CitPaymentRequest.php +++ b/src/Request/CitPaymentRequest.php @@ -24,7 +24,7 @@ class CitPaymentRequest extends AbstractPaymentRequest implements TokenPaymentRe protected $token; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/EmailRefundRequest.php b/src/Request/EmailRefundRequest.php index af32a6a..a4d4bd3 100644 --- a/src/Request/EmailRefundRequest.php +++ b/src/Request/EmailRefundRequest.php @@ -25,9 +25,8 @@ class EmailRefundRequest extends RefundRequest protected $email; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * - * @throws NestedValidationException Thrown when the validate() fails. * @throws ValidationException */ public function validate() diff --git a/src/Request/GetTokenRequest.php b/src/Request/GetTokenRequest.php index 72641ec..93aaba7 100644 --- a/src/Request/GetTokenRequest.php +++ b/src/Request/GetTokenRequest.php @@ -22,7 +22,7 @@ class GetTokenRequest implements \JsonSerializable protected $checkoutTokenizationId; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/MitPaymentRequest.php b/src/Request/MitPaymentRequest.php index 35d8b3f..3fecad9 100644 --- a/src/Request/MitPaymentRequest.php +++ b/src/Request/MitPaymentRequest.php @@ -24,7 +24,7 @@ class MitPaymentRequest extends AbstractPaymentRequest implements TokenPaymentRe protected $token; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/PaymentStatusRequest.php b/src/Request/PaymentStatusRequest.php index 0bc74df..25b0713 100644 --- a/src/Request/PaymentStatusRequest.php +++ b/src/Request/PaymentStatusRequest.php @@ -19,7 +19,7 @@ class PaymentStatusRequest protected $transactionId; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/RefundRequest.php b/src/Request/RefundRequest.php index 5c1cba8..4b34d83 100644 --- a/src/Request/RefundRequest.php +++ b/src/Request/RefundRequest.php @@ -23,7 +23,7 @@ class RefundRequest implements \JsonSerializable use JsonSerializable; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/RevertPaymentAuthHoldRequest.php b/src/Request/RevertPaymentAuthHoldRequest.php index 70eaa84..4ce275f 100644 --- a/src/Request/RevertPaymentAuthHoldRequest.php +++ b/src/Request/RevertPaymentAuthHoldRequest.php @@ -26,7 +26,7 @@ class RevertPaymentAuthHoldRequest implements \JsonSerializable protected $transactionId; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/ShopInShopPaymentRequest.php b/src/Request/ShopInShopPaymentRequest.php index b3c70f3..90634a1 100644 --- a/src/Request/ShopInShopPaymentRequest.php +++ b/src/Request/ShopInShopPaymentRequest.php @@ -20,7 +20,7 @@ class ShopInShopPaymentRequest extends PaymentRequest { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ From 921efdb4cd1d848e20bd7462f286bfb7bb44e15a Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:24:18 +0200 Subject: [PATCH 06/14] Fix wrong @var annotations --- src/Model/Item.php | 2 +- src/Request/AbstractPaymentRequest.php | 12 ++++++------ src/Request/RefundRequest.php | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 8e870c4..d2a8b02 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -97,7 +97,7 @@ class Item implements \JsonSerializable, ItemInterface * Merchant ID for the item. * Required for Shop-in-Shop payments, do not use for normal payments. * - * @var int + * @var string|null */ protected $merchant; diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index b952b0e..01cef0d 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -156,42 +156,42 @@ public function validate() /** * Array of items. * - * @var Item[] + * @var ItemInterface[] */ protected $items; /** * Customer information. * - * @var Customer + * @var CustomerInterface */ protected $customer; /** * Delivery address. * - * @var Address + * @var AddressInterface */ protected $deliveryAddress; /** * Invoicing address. * - * @var Address + * @var AddressInterface */ protected $invoicingAddress; /** * Where to redirect browser after a payment is paid or cancelled. * - * @var CallbackUrl; + * @var CallbackUrlInterface */ protected $redirectUrls; /** * Which url to ping after this payment is paid or cancelled. * - * @var CallbackUrl; + * @var CallbackUrlInterface */ protected $callbackUrls; diff --git a/src/Request/RefundRequest.php b/src/Request/RefundRequest.php index 4b34d83..5ac8af9 100644 --- a/src/Request/RefundRequest.php +++ b/src/Request/RefundRequest.php @@ -96,21 +96,21 @@ public function validate() /** * Refund recipient email address. * - * @var $mail + * @var string|null $email */ protected $email; /** * Merchant unique identifier for the refund. * - * @var $refundStamp + * @var string|null $refundStamp */ protected $refundStamp; /** * Refund reference. * - * @var $refundReference + * @var string|null $refundReference */ protected $refundReference; From 6d18422584328789030424ab38af33a23431f7fa Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:27:01 +0200 Subject: [PATCH 07/14] Add missing use --- src/Request/ShopInShopPaymentRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Request/ShopInShopPaymentRequest.php b/src/Request/ShopInShopPaymentRequest.php index 90634a1..7b63e3a 100644 --- a/src/Request/ShopInShopPaymentRequest.php +++ b/src/Request/ShopInShopPaymentRequest.php @@ -6,6 +6,7 @@ namespace Paytrail\SDK\Request; +use Paytrail\SDK\Exception\ValidationException; use Paytrail\SDK\Model\Item; /** From b69d532b8c2b17953493cd803171e6daa75c2cd7 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:59:41 +0200 Subject: [PATCH 08/14] Fix wrong class used in PaymentResponse --- src/Response/PaymentResponse.php | 4 ++-- tests/PaymentRequestTestCase.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Response/PaymentResponse.php b/src/Response/PaymentResponse.php index d280ab4..d1a8adb 100644 --- a/src/Response/PaymentResponse.php +++ b/src/Response/PaymentResponse.php @@ -141,8 +141,8 @@ public function getGroups(): array public function setGroups(array $groups): PaymentResponse { $this->groups = array_map(function ($group) { - if (! $group instanceof Provider) { - return (new Provider())->bindProperties($group); + if (! $group instanceof PaymentMethodGroup) { + return (new PaymentMethodGroup())->bindProperties($group); } return $group; diff --git a/tests/PaymentRequestTestCase.php b/tests/PaymentRequestTestCase.php index 730ba87..0928266 100644 --- a/tests/PaymentRequestTestCase.php +++ b/tests/PaymentRequestTestCase.php @@ -8,6 +8,7 @@ use Paytrail\SDK\Exception\HmacException; use Paytrail\SDK\Exception\ValidationException; use Paytrail\SDK\Interfaces\PaymentRequestInterface; +use Paytrail\SDK\Model\PaymentMethodGroup; use Paytrail\SDK\Request\PaymentRequest; use Paytrail\SDK\Request\ShopInShopPaymentRequest; use Paytrail\SDK\Response\PaymentResponse; @@ -98,6 +99,7 @@ public static function assertPaymentResponseIsValid(PaymentResponse $paymentResp static::assertNotEmpty($paymentResponse->getTerms()); static::assertNotEmpty($paymentResponse->getReference()); static::assertIsArray($paymentResponse->getGroups()); + static::assertContainsOnlyInstancesOf(PaymentMethodGroup::class, $paymentResponse->getGroups()); static::assertIsArray($paymentResponse->getProviders()); } } From 8232d0d68f51795480fc2a4cf53bab06109a15c1 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 20:03:29 +0200 Subject: [PATCH 09/14] Don't use dynamic properties (deprecated in PHP 8.2) --- tests/ClientTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index adf23a5..6cc088c 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -29,6 +29,10 @@ class ClientTest extends PaymentRequestTestCase protected $item2; + protected $shopInShopItem; + + protected $shopInShopItem2; + protected $redirect; protected $callback; From 6a3f95f178c8c2d2b962f17225b010bcd3187b52 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 20:08:30 +0200 Subject: [PATCH 10/14] Fix return type --- tests/Request/PaymentRequestTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Request/PaymentRequestTest.php b/tests/Request/PaymentRequestTest.php index 1da8411..20b26be 100644 --- a/tests/Request/PaymentRequestTest.php +++ b/tests/Request/PaymentRequestTest.php @@ -5,6 +5,7 @@ namespace Tests\Request; use Paytrail\SDK\Exception\ValidationException; +use Paytrail\SDK\Interfaces\PaymentRequestInterface; use Paytrail\SDK\Model\CallbackUrl; use Paytrail\SDK\Model\Customer; use Paytrail\SDK\Model\Item; @@ -37,7 +38,7 @@ public function testPaymentRequestWithoutItems(): void } } - private function getPaymentRequest(): PaymentRequest + private function getPaymentRequest(): PaymentRequestInterface { $payment = (new PaymentRequest()) ->setAmount(30) From fa438c61f89a057017bf807ef442b5378cf921e0 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Thu, 26 Jan 2023 13:08:27 +0200 Subject: [PATCH 11/14] Fix closure param type --- src/Request/AbstractPaymentRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index 01cef0d..93e5c6b 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -62,7 +62,7 @@ public function validate() }); // Count the total amount of the payment. - $items_total = array_reduce($this->getItems(), function ($carry = 0, ?Item $item = null) { + $items_total = array_reduce($this->getItems(), function ($carry = 0, ?ItemInterface $item = null) { if ($item === null) { return $carry; } From 62c5684f62cc7ef90ee55b10e653c9a414d7b3dc Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 20:15:25 +0200 Subject: [PATCH 12/14] Install phpstan static analyzer --- composer.json | 1 + phpstan.neon | 5 +++++ src/PaytrailClient.php | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index b39aad9..799d4bd 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "squizlabs/php_codesniffer": "^3.6", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.10", + "phpstan/phpstan": "1.9.14", "mockery/mockery": "^1.5", "guzzlehttp/guzzle": "^7.0|^6.0" }, diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..749a32d --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 3 + paths: + - src + - tests diff --git a/src/PaytrailClient.php b/src/PaytrailClient.php index 37471ae..752d2c6 100644 --- a/src/PaytrailClient.php +++ b/src/PaytrailClient.php @@ -98,8 +98,11 @@ protected function post( $headers = $this->reduceHeaders($response->getHeaders()); $this->validateHmac($headers, $body, $headers['signature'] ?? ''); } else { + // @phpstan-ignore-next-line FIXME $mac = $this->calculateHmac($data->toArray()); + // @phpstan-ignore-next-line FIXME $data->setSignature($mac); + // @phpstan-ignore-next-line FIXME $body = json_encode($data->toArray(), JSON_UNESCAPED_SLASHES); $response = $this->http_client->request('POST', $uri, [ From be1ee4b09b3d46591f393624d776285026420d3c Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 20:24:24 +0200 Subject: [PATCH 13/14] Run phpstan in workflow --- .github/workflows/run-workflow.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 4d9aca1..4c75e86 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -28,6 +28,14 @@ jobs: - name: Run linter run: composer lint + - name: Run phpstan + uses: php-actions/phpstan@v3.0.1 + with: + php_version: ${{ matrix.php-version }} + version: 1.9.14 + configuration: phpstan.neon + memory_limit: 256M + - name: Run tests uses: php-actions/phpunit@v3.0.0 with: From b3937f503eb2ade76e4340f58e0587eea73f2f22 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Thu, 26 Jan 2023 13:15:15 +0200 Subject: [PATCH 14/14] Add script "composer analyze" --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 799d4bd..b362b00 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,9 @@ } }, "scripts": { + "analyze": [ + "vendor/bin/phpstan" + ], "post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility", "post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility", "test": "\"vendor/bin/phpunit\"",