Skip to content

Commit

Permalink
Merge pull request #62 from mpesari/phpstan
Browse files Browse the repository at this point in the history
Install phpstan and fix some errors
  • Loading branch information
loueranta-paytrail authored Feb 15, 2023
2 parents 62e38c4 + b3937f5 commit 9430c8e
Show file tree
Hide file tree
Showing 32 changed files with 80 additions and 52 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/run-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -33,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\"",
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 3
paths:
- src
- tests
9 changes: 0 additions & 9 deletions src/Exception/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,13 @@

/**
* Class ValidationException
* This exception is a simple wrapper for
* a Respect\Validation NestedValidationException instance.
*
* This exception holds the general expection message
*
* @package Paytrail\SDK\Exception
*/
class ValidationException extends \Exception
{
/**
* Holds the previous NestedValidationException instance.
*
* $var NestedValidationException
*/
protected $previous;

/**
* Holds all error messages.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/AddressInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/CallbackUrlInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/CommissionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/CustomerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Interfaces/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/PaymentRequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Model/CallbackUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Model/Commission.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ public function setAmount(int $amount): Commission

/**
* The getter for the amount.
*
* @return string
*/
public function getAmount(): int
{
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Model/RefundItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Token/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
15 changes: 15 additions & 0 deletions src/PaytrailClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -86,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, [
Expand Down
16 changes: 8 additions & 8 deletions src/Request/AbstractPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Request/AddCardFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Request/CitPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Request/EmailRefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Request/GetTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Request/MitPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Request/PaymentStatusRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Request/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 9430c8e

Please sign in to comment.