Skip to content

Commit

Permalink
Support symfony 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiktor6 committed Sep 30, 2024
1 parent dd22f07 commit ef81063
Show file tree
Hide file tree
Showing 35 changed files with 181 additions and 378 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
deps:
- "normal"
- "low"

steps:
- name: "Checkout"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

steps:
- name: "Checkout"
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.0|^7.0",
"marc-mabe/php-enum": "^4.3",
"symfony/property-access": "6.4.*",
"symfony/serializer": "6.4.*"
"symfony/property-access": "6.4.*|^7.0",
"symfony/serializer": "6.4.*|^7.0"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^9.5",
"symfony/phpunit-bridge": "6.4.*",
"phpro/grumphp": "^v2.5",
"friendsofphp/php-cs-fixer": "^3.58",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-webmozart-assert": "^1.0"
"phpunit/phpunit": "^10.5",
"symfony/phpunit-bridge": "6.4.*|^7.0",
"phpro/grumphp": "^v2.8",
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-webmozart-assert": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 5 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="./vendor/autoload.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
cacheDirectory=".phpunit.cache"
beStrictAboutCoverageMetadata="true"
>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<env name="SYMFONY_WARNINGS_HELPER" value="weak"/>

</php>
<testsuites>
<testsuite name="Answear PayPo Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
48 changes: 8 additions & 40 deletions src/PayPo/Enum/OrderStatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,17 @@

namespace Answear\PayPo\Enum;

use MabeEnum\Enum;

class OrderStatusEnum extends Enum
enum OrderStatusEnum: string
{
public const NEW = 'NEW';
public const PENDING = 'PENDING';
public const ACCEPTED = 'ACCEPTED';
public const COMPLETED = 'COMPLETED';
public const REJECTED = 'REJECTED';
public const CANCELED = 'CANCELED';

public static function new(): self
{
return static::get(static::NEW);
}

public static function pending(): self
{
return static::get(static::PENDING);
}

public static function accepted(): self
{
return static::get(static::ACCEPTED);
}

public static function completed(): self
{
return static::get(static::COMPLETED);
}

public static function rejected(): self
{
return static::get(static::REJECTED);
}

public static function canceled(): self
{
return static::get(static::CANCELED);
}
case New = 'NEW';
case Pending = 'PENDING';
case Accepted = 'ACCEPTED';
case Completed = 'COMPLETED';
case Rejected = 'REJECTED';
case Canceled = 'CANCELED';

public function isFinal(): bool
{
return $this->is(self::completed()) || $this->is(self::rejected()) || $this->is(self::canceled());
return self::Completed === $this || self::Rejected === $this || self::Canceled === $this;
}
}
25 changes: 4 additions & 21 deletions src/PayPo/Enum/SettlementStatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@

namespace Answear\PayPo\Enum;

use MabeEnum\Enum;

class SettlementStatusEnum extends Enum
enum SettlementStatusEnum: string
{
public const NEW = 'NEW';
public const CONFIRMED = 'CONFIRMED';
public const PAID = 'PAID';

public static function new(): self
{
return static::get(static::NEW);
}

public static function confirmed(): self
{
return static::get(static::CONFIRMED);
}

public static function paid(): self
{
return static::get(static::PAID);
}
case New = 'NEW';
case Confirmed = 'CONFIRMED';
case Paid = 'PAID';
}
39 changes: 6 additions & 33 deletions src/PayPo/Enum/ShipmentEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,11 @@

namespace Answear\PayPo\Enum;

use MabeEnum\Enum;

class ShipmentEnum extends Enum
enum ShipmentEnum: int
{
public const COURIER = 0;
public const PICKUP_POINT = 1;
public const PARCEL_LOCKER = 2;
public const RUCH_PACK = 3;
public const CLICK_COLLECT = 4;

public static function clickCollect(): self
{
return static::get(static::CLICK_COLLECT);
}

public static function ruchPack(): self
{
return static::get(static::RUCH_PACK);
}

public static function parcelLocker(): self
{
return static::get(static::PARCEL_LOCKER);
}

public static function pickupPoint(): self
{
return static::get(static::PICKUP_POINT);
}

public static function courier(): self
{
return static::get(static::COURIER);
}
case Courier = 0;
case PickupPoint = 1;
case ParcelLocker = 2;
case RuchPack = 3;
case ClickCollect = 4;
}
16 changes: 5 additions & 11 deletions src/PayPo/Exception/BadResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

class BadResponseException extends \RuntimeException
{
private ResponseInterface $response;

public function __construct(ResponseInterface $response, ?\Throwable $t)
{
parent::__construct('Response error.', 0, $t);
$this->response = $response;
}

public function getResponse(): ResponseInterface
{
return $this->response;
public function __construct(
public readonly ResponseInterface $response,
?\Throwable $throwable,
) {
parent::__construct('Response error.', 0, $throwable);
}
}
14 changes: 4 additions & 10 deletions src/PayPo/Exception/PrepareRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

class PrepareRequestException extends \RuntimeException
{
private RequestInterface $request;

public function __construct(RequestInterface $request, ?\Throwable $t)
{
public function __construct(
public readonly RequestInterface $request,
?\Throwable $t,
) {
parent::__construct('Prepare request error.', 0, $t);
$this->request = $request;
}

public function getRequest(): RequestInterface
{
return $this->request;
}
}
22 changes: 4 additions & 18 deletions src/PayPo/Exception/SignatureNotValidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,10 @@

class SignatureNotValidException extends \InvalidArgumentException
{
private string $expectedSignature;
private ?string $providedSignature;

public function __construct(string $expectedSignature, ?string $providedSignature)
{
$this->expectedSignature = $expectedSignature;
$this->providedSignature = $providedSignature;

public function __construct(
public readonly string $expectedSignature,
public readonly ?string $providedSignature,
) {
parent::__construct('Signature is not valid');
}

public function getExpectedSignature(): string
{
return $this->expectedSignature;
}

public function getProvidedSignature(): ?string
{
return $this->providedSignature;
}
}
6 changes: 2 additions & 4 deletions src/PayPo/Request/Transaction/CancelRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ class CancelRequest implements RequestInterface
private const ENDPOINT = '/transactions';

public string $status;
private string $transactionUuid;

public function __construct(string $transactionUuid)
public function __construct(private readonly string $transactionUuid)
{
$this->status = OrderStatusEnum::CANCELED;
$this->transactionUuid = $transactionUuid;
$this->status = OrderStatusEnum::Canceled->value;
}

public function getHttpMethod(): string
Expand Down
6 changes: 2 additions & 4 deletions src/PayPo/Request/Transaction/ConfirmRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ class ConfirmRequest implements RequestInterface
private const ENDPOINT = '/transactions';

public string $status;
private string $transactionUuid;

public function __construct(string $transactionUuid)
public function __construct(private readonly string $transactionUuid)
{
$this->status = OrderStatusEnum::COMPLETED;
$this->transactionUuid = $transactionUuid;
$this->status = OrderStatusEnum::Completed->value;
}

public function getHttpMethod(): string
Expand Down
12 changes: 3 additions & 9 deletions src/PayPo/Request/Transaction/CreateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@ class CreateRequest implements RequestInterface

public string $merchantId;
public ?string $shopId = null;
public Order $order;
public Customer $customer;
public Configuration $configuration;

public function __construct(
Order $order,
Customer $customer,
Configuration $configuration
public readonly Order $order,
public readonly Customer $customer,
public readonly Configuration $configuration,
) {
$this->merchantId = PayPoConfiguration::getClientId();
$this->order = $order;
$this->customer = $customer;
$this->configuration = $configuration;
}

public function getHttpMethod(): string
Expand Down
11 changes: 4 additions & 7 deletions src/PayPo/Request/Transaction/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ class RefundRequest implements RequestInterface
private const HTTP_METHOD = 'POST';
private const ENDPOINT = '/transactions';

private string $transactionUuid;
public int $amount;

public function __construct(string $transactionUuid, int $amount)
{
$this->transactionUuid = $transactionUuid;
$this->amount = $amount;
public function __construct(
private readonly string $transactionUuid,
public readonly int $amount,
) {
}

public function getHttpMethod(): string
Expand Down
5 changes: 1 addition & 4 deletions src/PayPo/Request/Transaction/StatusDetailsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ class StatusDetailsRequest implements RequestInterface
private const HTTP_METHOD = 'GET';
private const ENDPOINT = '/transactions';

private string $transactionId;

public function __construct(string $transactionId)
public function __construct(private readonly string $transactionId)
{
$this->transactionId = $transactionId;
}

public function getHttpMethod(): string
Expand Down
Loading

0 comments on commit ef81063

Please sign in to comment.