Skip to content

Commit

Permalink
fix: use native enums
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Dec 25, 2021
1 parent e19778a commit f1ae952
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 236 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
timeout-minutes: 5
strategy:
matrix:
php-version: [8.0]
php-version: [8.1]

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
timeout-minutes: 5
strategy:
matrix:
php-version: [8.0]
php-version: [8.1]

steps:
- name: Checkout code
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
"authors": [
{
"name": "Ivan Stasiuk",
"email": "brokeyourbike@gmail.com",
"homepage": "https://github.com/brokeyourbike"
"email": "ivan@stasi.uk",
"homepage": "https://stasi.uk"
}
],
"minimum-stability": "stable",
"require": {
"php": "^8.0",
"php": "^8.1",
"brokeyourbike/http-client": "^1.0",
"brokeyourbike/resolve-uri": "^1.0",
"myclabs/php-enum": "^1.8",
"brokeyourbike/http-enums": "^1.0",
"brokeyourbike/http-enums": "^2.0",
"brokeyourbike/has-source-model": "^2.0",
"psr/simple-cache": "^1.0",
"nesbot/carbon": "^2"
Expand Down
50 changes: 5 additions & 45 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,52 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:DUPLICATE_TRANSACTION is unused\\.$#"
message: "#^Access to an undefined property BrokeYourBike\\\\HttpEnums\\\\HttpMethodEnum\\:\\:\\$value\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php
path: src/Client.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:ERROR is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:INVALID_ACCOUNT is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:SUCCESS is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:SYSTEM_EXCEPTION is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:UNAUTHENTICATED is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:WRONG_REQUEST is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\PostedStatusEnum\\:\\:NO is unused\\.$#"
count: 1
path: src/Enums/PostedStatusEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\PostedStatusEnum\\:\\:YES is unused\\.$#"
count: 1
path: src/Enums/PostedStatusEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\StatusCodeEnum\\:\\:PROCESSED is unused\\.$#"
count: 1
path: src/Enums/StatusCodeEnum.php
message: "#^Access to undefined constant BrokeYourBike\\\\HttpEnums\\\\HttpMethodEnum\\:\\:POST\\.$#"
count: 8
path: src/Client.php

22 changes: 11 additions & 11 deletions src/Client.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>.
// Copyright (C) 2021 Ivan Stasiuk <ivan@stasi.uk>.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand All @@ -23,7 +23,7 @@
use BrokeYourBike\HasSourceModel\HasSourceModelInterface;

/**
* @author Ivan Stasiuk <brokeyourbike@gmail.com>
* @author Ivan Stasiuk <ivan@stasi.uk>
*/
class Client implements HttpClientInterface, HasSourceModelInterface
{
Expand Down Expand Up @@ -99,37 +99,37 @@ public function fetchAuthTokenRaw(): ResponseInterface
$uri = (string) $this->resolveUriFor($this->config->getUrl(), 'api/authentication/getToken');

return $this->httpClient->request(
(string) HttpMethodEnum::POST(),
HttpMethodEnum::POST->value,
$uri,
$options
);
}

public function fetchBalanceRaw(string $accountNumber): ResponseInterface
{
return $this->performRequest(HttpMethodEnum::POST(), 'api/enquiry/balance', [
return $this->performRequest(HttpMethodEnum::POST, 'api/enquiry/balance', [
'accountNumber' => $accountNumber,
]);
}

public function fetchAccountRaw(string $bankCode, string $accountNumber): ResponseInterface
{
return $this->performRequest(HttpMethodEnum::POST(), 'api/enquiry/accountEnquiry', [
return $this->performRequest(HttpMethodEnum::POST, 'api/enquiry/accountEnquiry', [
'destinationBankCode' => $bankCode,
'accountNumber' => $accountNumber,
]);
}

public function fetchDomesticAccountRaw(string $accountNumber): ResponseInterface
{
return $this->performRequest(HttpMethodEnum::POST(), 'api/enquiry/domAccountEnquiry', [
return $this->performRequest(HttpMethodEnum::POST, 'api/enquiry/domAccountEnquiry', [
'accountNumber' => $accountNumber,
]);
}

public function fetchDomesticTransactionRaw(string $reference): ResponseInterface
{
return $this->performRequest(HttpMethodEnum::POST(), 'api/enquiry/domTransaction', [
return $this->performRequest(HttpMethodEnum::POST, 'api/enquiry/domTransaction', [
'transactionReference' => $reference,
]);
}
Expand All @@ -140,7 +140,7 @@ public function sendDomesticTransaction(TransactionInterface $transaction): Resp
$this->setSourceModel($transaction);
}

return $this->performRequest(HttpMethodEnum::POST(), 'api/transaction/zenithDomTransfer', [
return $this->performRequest(HttpMethodEnum::POST, 'api/transaction/zenithDomTransfer', [
'transactionReference' => $transaction->getReference(),
'paymentReference' => $transaction->getReference(),
'senderName' => $transaction->getSenderName(),
Expand All @@ -154,14 +154,14 @@ public function sendDomesticTransaction(TransactionInterface $transaction): Resp

public function fetchTransactionRaw(string $reference): ResponseInterface
{
return $this->performRequest(HttpMethodEnum::POST(), 'api/enquiry/transaction', [
return $this->performRequest(HttpMethodEnum::POST, 'api/enquiry/transaction', [
'transactionReference' => $reference,
]);
}

public function transactionLookupRaw(string $accountNumber, \DateTime $transactionDate): ResponseInterface
{
return $this->performRequest(HttpMethodEnum::POST(), 'api/enquiry/transactionLookup', [
return $this->performRequest(HttpMethodEnum::POST, 'api/enquiry/transactionLookup', [
'accountNumber' => $accountNumber,
'transactionDate' => $transactionDate->format('Y-m-d'),
]);
Expand Down Expand Up @@ -189,6 +189,6 @@ private function performRequest(HttpMethodEnum $method, string $uri, array $data
}

$uri = (string) $this->resolveUriFor($this->config->getUrl(), $uri);
return $this->httpClient->request((string) $method, $uri, $options);
return $this->httpClient->request($method->value, $uri, $options);
}
}
29 changes: 10 additions & 19 deletions src/Enums/ErrorCodeEnum.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>.
// Copyright (C) 2021 Ivan Stasiuk <ivan@stasi.uk>.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand All @@ -9,24 +9,15 @@
namespace BrokeYourBike\ZenithBank\Enums;

/**
* @author Ivan Stasiuk <brokeyourbike@gmail.com>
*
* @method static ErrorCodeEnum SUCCESS()
* @method static ErrorCodeEnum DUPLICATE_TRANSACTION()
* @method static ErrorCodeEnum WRONG_REQUEST()
* @method static ErrorCodeEnum UNAUTHENTICATED()
* @method static ErrorCodeEnum ERROR()
* @method static ErrorCodeEnum INVALID_ACCOUNT()
* @method static ErrorCodeEnum SYSTEM_EXCEPTION()
* @psalm-immutable
* @author Ivan Stasiuk <ivan@stasi.uk>
*/
final class ErrorCodeEnum extends \MyCLabs\Enum\Enum
enum ErrorCodeEnum: string
{
private const SUCCESS = '00';
private const DUPLICATE_TRANSACTION = '01';
private const WRONG_REQUEST = '02';
private const UNAUTHENTICATED = '06';
private const ERROR = '11';
private const INVALID_ACCOUNT = '13';
private const SYSTEM_EXCEPTION = '14';
case SUCCESS = '00';
case DUPLICATE_TRANSACTION = '01';
case WRONG_REQUEST = '02';
case UNAUTHENTICATED = '06';
case ERROR = '11';
case INVALID_ACCOUNT = '13';
case SYSTEM_EXCEPTION = '14';
}
12 changes: 4 additions & 8 deletions src/Enums/PostedStatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
namespace BrokeYourBike\ZenithBank\Enums;

/**
* @author Ivan Stasiuk <brokeyourbike@gmail.com>
*
* @method static PostedStatusEnum YES()
* @method static PostedStatusEnum NO()
* @psalm-immutable
* @author Ivan Stasiuk <ivan@stasi.uk>
*/
final class PostedStatusEnum extends \MyCLabs\Enum\Enum
enum PostedStatusEnum: string
{
private const YES = 'Y';
private const NO = 'N';
case YES = 'Y';
case NO = 'N';
}
11 changes: 4 additions & 7 deletions src/Enums/StatusCodeEnum.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>.
// Copyright (C) 2021 Ivan Stasiuk <ivan@stasi.uk>.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand All @@ -9,15 +9,12 @@
namespace BrokeYourBike\ZenithBank\Enums;

/**
* @author Ivan Stasiuk <brokeyourbike@gmail.com>
*
* @method static StatusCodeEnum PROCESSED()
* @psalm-immutable
* @author Ivan Stasiuk <ivan@stasi.uk>
*/
final class StatusCodeEnum extends \MyCLabs\Enum\Enum
enum StatusCodeEnum: string
{
/**
* Transaction processed.
*/
private const PROCESSED = 'PROCESSED';
case PROCESSED = 'PROCESSED';
}
4 changes: 2 additions & 2 deletions src/Interfaces/ConfigInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>.
// Copyright (C) 2021 Ivan Stasiuk <ivan@stasi.uk>.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand All @@ -9,7 +9,7 @@
namespace BrokeYourBike\ZenithBank\Interfaces;

/**
* @author Ivan Stasiuk <brokeyourbike@gmail.com>
* @author Ivan Stasiuk <ivan@stasi.uk>
*/
interface ConfigInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/TransactionInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>.
// Copyright (C) 2021 Ivan Stasiuk <ivan@stasi.uk>.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand All @@ -9,7 +9,7 @@
namespace BrokeYourBike\ZenithBank\Interfaces;

/**
* @author Ivan Stasiuk <brokeyourbike@gmail.com>
* @author Ivan Stasiuk <ivan@stasi.uk>
*/
interface TransactionInterface
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>.
// Copyright (C) 2021 Ivan Stasiuk <ivan@stasi.uk>.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand All @@ -18,7 +18,7 @@
use BrokeYourBike\HasSourceModel\HasSourceModelInterface;

/**
* @author Ivan Stasiuk <brokeyourbike@gmail.com>
* @author Ivan Stasiuk <ivan@stasi.uk>
*/
class ClientTest extends TestCase
{
Expand Down
37 changes: 0 additions & 37 deletions tests/Enums/ErrorCodeEnumTest.php

This file was deleted.

Loading

0 comments on commit f1ae952

Please sign in to comment.