From 0fab93cc92df64207ffc24e2c5d4d4f78d163dcf Mon Sep 17 00:00:00 2001 From: CyberVitexus Date: Sun, 1 Dec 2024 05:50:01 +0100 Subject: [PATCH] Strict Types update Code reformat --- .../templates/Statementor.mustache | 18 ++-- debian/composer.json | 2 +- examples/download-statements.php | 8 +- lib/ApiClient.php | 2 +- lib/ObjectSerializer.php | 8 +- lib/PremiumAPI/DownloadStatementApi.php | 12 +-- lib/PremiumAPI/GetAccountBalanceApi.php | 12 +-- lib/PremiumAPI/GetAccountsApi.php | 12 +-- lib/PremiumAPI/GetBatchDetailApi.php | 12 +-- lib/PremiumAPI/GetStatementListApi.php | 12 +-- lib/PremiumAPI/GetTransactionListApi.php | 12 +-- lib/PremiumAPI/UploadPaymentsApi.php | 12 +-- lib/Statementor.php | 18 ++-- lib/Transactor.php | 96 +++++++++---------- 14 files changed, 118 insertions(+), 118 deletions(-) diff --git a/.openapi-generator/templates/Statementor.mustache b/.openapi-generator/templates/Statementor.mustache index 8e4137f..3d71472 100644 --- a/.openapi-generator/templates/Statementor.mustache +++ b/.openapi-generator/templates/Statementor.mustache @@ -42,11 +42,11 @@ class Statementor extends \Ease\Sand if ($accountNumber) { $this->setAccountNumber($accountNumber); } - - if ($scope){ + + if ($scope) { $this->setScope($scope); } - + } /** @@ -71,7 +71,7 @@ class Statementor extends \Ease\Sand * * @return array */ - public function getStatements($currencyCode = 'CZK', $statementLine = 'MAIN') + public function getStatements($currencyCode = 'CZK', $statementLine = 'MAIN'): array { $apiInstance = new PremiumAPI\GetStatementListApi(); $page = 0; @@ -213,13 +213,13 @@ class Statementor extends \Ease\Sand * Save Statement PDF files * * @param string $saveTo - * @param array $statements + * @param array $statements - produced by getStatements() function * @param string $format pdf|xml * @param string $currencyCode * - * @return string + * @return array */ - public function download(string $saveTo, array $statements, $format = 'pdf', $currencyCode = 'CZK') + public function download(string $saveTo, array $statements, string $format = 'pdf', string $currencyCode = 'CZK'): array { $saved = []; $apiInstance = new PremiumAPI\DownloadStatementApi(); @@ -252,7 +252,7 @@ class Statementor extends \Ease\Sand * * @return \DateTime */ - public function getSince() + public function getSince(): \DateTime { return $this->since; } @@ -262,7 +262,7 @@ class Statementor extends \Ease\Sand * * @return \DateTime */ - public function getUntil() + public function getUntil(): \DateTime { return $this->until; } diff --git a/debian/composer.json b/debian/composer.json index 8bd1021..9a05a5c 100644 --- a/debian/composer.json +++ b/debian/composer.json @@ -1,7 +1,7 @@ { "name": "deb/rbczpremiumapi", "description": "An Core of PHP Framework for Ease of writing Applications (debianized)", - "version": "1.2.2", + "version": "1.2.3", "authors": [ { "name": "Vítězslav Dvořák", diff --git a/examples/download-statements.php b/examples/download-statements.php index b33f49e..8b7a7bf 100644 --- a/examples/download-statements.php +++ b/examples/download-statements.php @@ -14,11 +14,11 @@ * Get today's transactions list */ \Ease\Shared::init(['CERT_PASS', 'XIBMCLIENTID', 'ACCOUNT_NUMBER'], isset($argv[1]) ? $argv[1] : '../.env'); -ApiClient::checkCertificatePresence(\Ease\Functions::cfg('CERT_FILE')); -$engine = new Statementor(\Ease\Functions::cfg('ACCOUNT_NUMBER')); -$engine->setScope(\Ease\Functions::cfg('STATEMENT_IMPORT_SCOPE', 'last_month')); +ApiClient::checkCertificatePresence(\Ease\Shared::cfg('CERT_FILE')); +$engine = new Statementor(\Ease\Shared::cfg('ACCOUNT_NUMBER')); +$engine->setScope(\Ease\Shared::cfg('STATEMENT_IMPORT_SCOPE', 'last_month')); -$saveTo = \Ease\Functions::cfg('STATEMENT_SAVE_DIR', './'); +$saveTo = \Ease\Shared::cfg('STATEMENT_SAVE_DIR', './'); if (file_exists($saveTo) === false) { mkdir($saveTo, 0777, true); diff --git a/lib/ApiClient.php b/lib/ApiClient.php index 1bd5c43..84fe1a1 100644 --- a/lib/ApiClient.php +++ b/lib/ApiClient.php @@ -149,10 +149,10 @@ public static function sourceString() /** * Try to check certificate readibilty * - * @throws Exception - Certificate file not found * * @param string $certFile path to certificate * @param boolean $die throw exception or return false ? + * @throws Exception - Certificate file not found * * @return boolean certificate file */ diff --git a/lib/ObjectSerializer.php b/lib/ObjectSerializer.php index ed6500d..7320e4a 100644 --- a/lib/ObjectSerializer.php +++ b/lib/ObjectSerializer.php @@ -193,12 +193,12 @@ private static function isEmptyValue($value, string $openApiType): bool case 'float': return $value !== 0 && $value !== 0.0; - # For boolean values, '' is considered empty + # For boolean values, '' is considered empty case 'bool': case 'boolean': return !in_array($value, [false, 0], true); - # For all the other types, any value at this point can be considered empty. + # For all the other types, any value at this point can be considered empty. default: return true; } @@ -239,7 +239,7 @@ public static function toQueryValue( } # Handle DateTime objects in query - if ( (($openApiType === "\\DateTime") || $openApiType === 'string') && $value instanceof \DateTime) { + if ((($openApiType === "\\DateTime") || $openApiType === 'string') && $value instanceof \DateTime) { return ["{$paramName}" => $value->format(self::$dateTimeFormat)]; } @@ -294,7 +294,7 @@ public static function toQueryValue( */ public static function convertBoolToQueryStringFormat(bool $value) { - if (Configuration::BOOLEAN_FORMAT_STRING == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()) { + if (Configuration::BOOLEAN_FORMAT_STRING === Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()) { return $value ? 'true' : 'false'; } diff --git a/lib/PremiumAPI/DownloadStatementApi.php b/lib/PremiumAPI/DownloadStatementApi.php index 0a8ee5a..601417b 100644 --- a/lib/PremiumAPI/DownloadStatementApi.php +++ b/lib/PremiumAPI/DownloadStatementApi.php @@ -97,12 +97,12 @@ class DownloadStatementApi ], ]; -/** - * @param ClientInterface $client - * @param Configuration $config - * @param HeaderSelector $selector - * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec - */ + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ public function __construct( ClientInterface $client = null, Configuration $config = null, diff --git a/lib/PremiumAPI/GetAccountBalanceApi.php b/lib/PremiumAPI/GetAccountBalanceApi.php index 481c91d..93dc166 100644 --- a/lib/PremiumAPI/GetAccountBalanceApi.php +++ b/lib/PremiumAPI/GetAccountBalanceApi.php @@ -97,12 +97,12 @@ class GetAccountBalanceApi ], ]; -/** - * @param ClientInterface $client - * @param Configuration $config - * @param HeaderSelector $selector - * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec - */ + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ public function __construct( ClientInterface $client = null, Configuration $config = null, diff --git a/lib/PremiumAPI/GetAccountsApi.php b/lib/PremiumAPI/GetAccountsApi.php index 8a3494f..8404db9 100644 --- a/lib/PremiumAPI/GetAccountsApi.php +++ b/lib/PremiumAPI/GetAccountsApi.php @@ -97,12 +97,12 @@ class GetAccountsApi ], ]; -/** - * @param ClientInterface $client - * @param Configuration $config - * @param HeaderSelector $selector - * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec - */ + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ public function __construct( ClientInterface $client = null, Configuration $config = null, diff --git a/lib/PremiumAPI/GetBatchDetailApi.php b/lib/PremiumAPI/GetBatchDetailApi.php index 71571c9..a5f97b3 100644 --- a/lib/PremiumAPI/GetBatchDetailApi.php +++ b/lib/PremiumAPI/GetBatchDetailApi.php @@ -97,12 +97,12 @@ class GetBatchDetailApi ], ]; -/** - * @param ClientInterface $client - * @param Configuration $config - * @param HeaderSelector $selector - * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec - */ + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ public function __construct( ClientInterface $client = null, Configuration $config = null, diff --git a/lib/PremiumAPI/GetStatementListApi.php b/lib/PremiumAPI/GetStatementListApi.php index defe80a..309031b 100644 --- a/lib/PremiumAPI/GetStatementListApi.php +++ b/lib/PremiumAPI/GetStatementListApi.php @@ -97,12 +97,12 @@ class GetStatementListApi ], ]; -/** - * @param ClientInterface $client - * @param Configuration $config - * @param HeaderSelector $selector - * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec - */ + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ public function __construct( ClientInterface $client = null, Configuration $config = null, diff --git a/lib/PremiumAPI/GetTransactionListApi.php b/lib/PremiumAPI/GetTransactionListApi.php index 8deff11..55c3d72 100644 --- a/lib/PremiumAPI/GetTransactionListApi.php +++ b/lib/PremiumAPI/GetTransactionListApi.php @@ -97,12 +97,12 @@ class GetTransactionListApi ], ]; -/** - * @param ClientInterface $client - * @param Configuration $config - * @param HeaderSelector $selector - * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec - */ + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ public function __construct( ClientInterface $client = null, Configuration $config = null, diff --git a/lib/PremiumAPI/UploadPaymentsApi.php b/lib/PremiumAPI/UploadPaymentsApi.php index d60bf25..3d07c0f 100644 --- a/lib/PremiumAPI/UploadPaymentsApi.php +++ b/lib/PremiumAPI/UploadPaymentsApi.php @@ -97,12 +97,12 @@ class UploadPaymentsApi ], ]; -/** - * @param ClientInterface $client - * @param Configuration $config - * @param HeaderSelector $selector - * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec - */ + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ public function __construct( ClientInterface $client = null, Configuration $config = null, diff --git a/lib/Statementor.php b/lib/Statementor.php index 0a3213a..4db0919 100644 --- a/lib/Statementor.php +++ b/lib/Statementor.php @@ -42,11 +42,11 @@ public function __construct(string $accountNumber = '', string $scope = '') if ($accountNumber) { $this->setAccountNumber($accountNumber); } - - if ($scope){ + + if ($scope) { $this->setScope($scope); } - + } /** @@ -71,7 +71,7 @@ public function setAccountNumber($accountNumber) * * @return array */ - public function getStatements($currencyCode = 'CZK', $statementLine = 'MAIN') + public function getStatements($currencyCode = 'CZK', $statementLine = 'MAIN'): array { $apiInstance = new PremiumAPI\GetStatementListApi(); $page = 0; @@ -213,13 +213,13 @@ public function setScope(string $scope): void * Save Statement PDF files * * @param string $saveTo - * @param array $statements + * @param array $statements - produced by getStatements() function * @param string $format pdf|xml * @param string $currencyCode * - * @return string + * @return array */ - public function download(string $saveTo, array $statements, $format = 'pdf', $currencyCode = 'CZK') + public function download(string $saveTo, array $statements, string $format = 'pdf', string $currencyCode = 'CZK'): array { $saved = []; $apiInstance = new PremiumAPI\DownloadStatementApi(); @@ -252,7 +252,7 @@ public function download(string $saveTo, array $statements, $format = 'pdf', $cu * * @return \DateTime */ - public function getSince() + public function getSince(): \DateTime { return $this->since; } @@ -262,7 +262,7 @@ public function getSince() * * @return \DateTime */ - public function getUntil() + public function getUntil(): \DateTime { return $this->until; } diff --git a/lib/Transactor.php b/lib/Transactor.php index a6502df..9e0a2b1 100644 --- a/lib/Transactor.php +++ b/lib/Transactor.php @@ -65,7 +65,7 @@ public function getTransactions() */ public function import() { -// $allMoves = $this->getColumnsFromPohoda('id', ['limit' => 0, 'banka' => $this->bank]); + // $allMoves = $this->getColumnsFromPohoda('id', ['limit' => 0, 'banka' => $this->bank]); $allTransactions = $this->getTransactions(); $this->addStatusMessage(count($allTransactions) . ' transactions obtained via API', 'debug'); $success = 0; @@ -85,7 +85,7 @@ public function import() */ public function takeTransactionData($transactionData) { -// $this->setMyKey(\Pohoda\RO::code('RB' . $transactionData->entryReference)); + // $this->setMyKey(\Pohoda\RO::code('RB' . $transactionData->entryReference)); $moveTrans = [ 'DBIT' => 'expense', 'CRDT' => 'receipt' @@ -96,53 +96,53 @@ public function takeTransactionData($transactionData) $this->setDataValue('intNote', _('Automatic Import') . ': ' . \Ease\Shared::appName() . ' ' . \Ease\Shared::appVersion() . ' ' . $transactionData->entryReference); $this->setDataValue('statementNumber', ['statementNumber' => $transactionData->bankTransactionCode->code]); $counterAccount = $transactionData->entryDetails->transactionDetails->relatedParties->counterParty; -//$bankRecord = [ -//// "MOSS" => ['ids' => 'AB'], -// 'account' => 'KB', -//// "accounting", -//// "accountingPeriodMOSS", -//// "activity" => 'testing', -// 'bankType' => 'receipt', -//// "centre", -//// "classificationKVDPH", -//// "classificationVAT", -// "contract" => 'n/a', -// "datePayment" => date('Y-m-d'), -// "dateStatement" => date('Y-m-d'), -//// "evidentiaryResourcesMOSS", -// "intNote" => 'Import works well', -//// "myIdentity", -// "note" => 'Automated import', -// 'partnerIdentity' => ['address' => ['street' => 'dlouha'], 'shipToAddress' => ['street' => 'kratka']], -// "paymentAccount" => ['accountNo' => '1234', 'bankCode' => '5500'], -// 'statementNumber' => [ -// 'statementNumber' => (string) time(), -// //'numberMovement' => (string) time() -// ], -//// "symConst" => 'XX', -//// ?"symPar", -// "symSpec" => '23', -// "symVar" => (string) time(), -// "text" => 'Testing income ' . time(), -// 'homeCurrency' => ['priceNone' => '1001'] -//]; -// $this->setDataValue('cisDosle', $transactionData->entryReference); + //$bankRecord = [ + //// "MOSS" => ['ids' => 'AB'], + // 'account' => 'KB', + //// "accounting", + //// "accountingPeriodMOSS", + //// "activity" => 'testing', + // 'bankType' => 'receipt', + //// "centre", + //// "classificationKVDPH", + //// "classificationVAT", + // "contract" => 'n/a', + // "datePayment" => date('Y-m-d'), + // "dateStatement" => date('Y-m-d'), + //// "evidentiaryResourcesMOSS", + // "intNote" => 'Import works well', + //// "myIdentity", + // "note" => 'Automated import', + // 'partnerIdentity' => ['address' => ['street' => 'dlouha'], 'shipToAddress' => ['street' => 'kratka']], + // "paymentAccount" => ['accountNo' => '1234', 'bankCode' => '5500'], + // 'statementNumber' => [ + // 'statementNumber' => (string) time(), + // //'numberMovement' => (string) time() + // ], + //// "symConst" => 'XX', + //// ?"symPar", + // "symSpec" => '23', + // "symVar" => (string) time(), + // "text" => 'Testing income ' . time(), + // 'homeCurrency' => ['priceNone' => '1001'] + //]; + // $this->setDataValue('cisDosle', $transactionData->entryReference); if (property_exists($transactionData->entryDetails->transactionDetails->remittanceInformation, 'creditorReferenceInformation')) { if (property_exists($transactionData->entryDetails->transactionDetails->remittanceInformation->creditorReferenceInformation, 'variable')) { $this->setDataValue('symVar', $transactionData->entryDetails->transactionDetails->remittanceInformation->creditorReferenceInformation->variable); } -// if (property_exists($transactionData->entryDetails->transactionDetails->remittanceInformation->creditorReferenceInformation, 'constant')) { -// $conSym = $transactionData->entryDetails->transactionDetails->remittanceInformation->creditorReferenceInformation->constant; -// if (intval($conSym)) { -// $conSym = sprintf('%04d', $conSym); -// $this->ensureKSExists($conSym); -// $this->setDataValue('konSym', \Pohoda\RO::code($conSym)); -// } -// } + // if (property_exists($transactionData->entryDetails->transactionDetails->remittanceInformation->creditorReferenceInformation, 'constant')) { + // $conSym = $transactionData->entryDetails->transactionDetails->remittanceInformation->creditorReferenceInformation->constant; + // if (intval($conSym)) { + // $conSym = sprintf('%04d', $conSym); + // $this->ensureKSExists($conSym); + // $this->setDataValue('konSym', \Pohoda\RO::code($conSym)); + // } + // } } -// $this->setDataValue('datVyst', $transactionData->bookingDate); + // $this->setDataValue('datVyst', $transactionData->bookingDate); //$this->setDataValue('duzpPuv', $transactionData->valueDate); if (property_exists($transactionData->entryDetails->transactionDetails->remittanceInformation, 'originatorMessage')) { $this->setDataValue('text', $transactionData->entryDetails->transactionDetails->remittanceInformation->originatorMessage); @@ -151,7 +151,7 @@ public function takeTransactionData($transactionData) $this->setDataValue('note', 'Import Job ' . \Ease\Shared::cfg('JOB_ID', 'n/a')); if (property_exists($transactionData->entryDetails->transactionDetails->relatedParties, 'counterParty')) { if (property_exists($transactionData->entryDetails->transactionDetails->relatedParties->counterParty, 'name')) { -//TODO $this->setDataValue('nazFirmy', $transactionData->entryDetails->transactionDetails->relatedParties->counterParty->name); + //TODO $this->setDataValue('nazFirmy', $transactionData->entryDetails->transactionDetails->relatedParties->counterParty->name); } @@ -164,15 +164,15 @@ public function takeTransactionData($transactionData) $this->setDataValue('paymentAccount', ['accountNo' => $accountNumber, 'bankCode' => $counterAccount->organisationIdentification->bankCode]); $amount = strval(abs($transactionData->amount->value)); - if ($transactionData->amount->currency == 'CZK') { + if ($transactionData->amount->currency === 'CZK') { $this->setDataValue('homeCurrency', ['priceNone' => $amount]); } else { $this->setDataValue('foreginCurrency', ['priceNone' => $amount]); //TODO: Not tested } } -// $this->setDataValue('source', $this->sourceString()); -// echo $this->getJsonizedData() . "\n"; + // $this->setDataValue('source', $this->sourceString()); + // echo $this->getJsonizedData() . "\n"; } /** @@ -180,7 +180,7 @@ public function takeTransactionData($transactionData) * * @throws \Exception */ - function setScope(string $scope) + public function setScope(string $scope) { switch ($scope) { case 'today': @@ -212,7 +212,7 @@ function setScope(string $scope) } break; } - if ($scope != 'auto' && $scope != 'today' && $scope != 'yesterday') { + if ($scope !== 'auto' && $scope !== 'today' && $scope !== 'yesterday') { $this->since = $this->since->setTime(0, 0); $this->until = $this->until->setTime(0, 0); }