diff --git a/.editorconfig b/.editorconfig index 3faf149..5e5b915 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,6 @@ indent_style = tab indent_size = tab tab_width = 4 -[{*.json, *.yaml, *.yml, *.md}] +[*.{json,yaml,yml,md}] indent_style = space indent_size = 2 diff --git a/.gitattributes b/.gitattributes index c52e7b9..5c3dfac 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,10 +1,8 @@ -# Not archived .docs export-ignore -tests export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.travis.yml export-ignore +Makefile export-ignore phpstan.neon export-ignore -README.md export-ignore ruleset.xml export-ignore +tests export-ignore diff --git a/.github/.kodiak.toml b/.github/.kodiak.toml deleted file mode 100644 index 60c34b6..0000000 --- a/.github/.kodiak.toml +++ /dev/null @@ -1,10 +0,0 @@ -version = 1 - -[merge] -automerge_label = "automerge" -blacklist_title_regex = "^WIP.*" -blacklist_labels = ["WIP"] -method = "rebase" -delete_branch_on_merge = true -notify_on_conflict = true -optimistic_updates = false diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 860c47e..fac01f8 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -8,7 +8,7 @@ on: branches: ["*"] schedule: - - cron: "0 8 * * 1" + - cron: "0 9 * * 1" jobs: coverage: diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml deleted file mode 100644 index eb916bf..0000000 --- a/.github/workflows/phpstan.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: "Phpstan" - -on: - pull_request: - workflow_dispatch: - - push: - branches: ["*"] - - schedule: - - cron: "0 8 * * 1" - -jobs: - phpstan: - name: "Phpstan" - uses: contributte/.github/.github/workflows/phpstan.yml@master - with: - php: "8.2" diff --git a/.github/workflows/codesniffer.yml b/.github/workflows/qa.yml similarity index 64% rename from .github/workflows/codesniffer.yml rename to .github/workflows/qa.yml index a58ac4f..f66e0ab 100644 --- a/.github/workflows/codesniffer.yml +++ b/.github/workflows/qa.yml @@ -1,4 +1,4 @@ -name: "Codesniffer" +name: "QA" on: pull_request: @@ -11,6 +11,12 @@ on: - cron: "0 8 * * 1" jobs: + phpstan: + name: "PHPStan" + uses: contributte/.github/.github/workflows/phpstan.yml@master + with: + php: "8.2" + codesniffer: name: "Codesniffer" uses: contributte/.github/.github/workflows/codesniffer.yml@master diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed53ba5..7d85dd5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,15 +35,9 @@ jobs: with: php: "8.2" - test81: - name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@master - with: - php: "8.1" - testlower: name: "Nette Tester" uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.1" + php: "8.2" composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" diff --git a/.gitignore b/.gitignore index b1b6f4d..8ff0a93 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,9 @@ /composer.lock # Tests -/temp -/coverage.xml +/tests/tmp +/tests/**/*.log +/tests/**/*.html +/tests/**/*.expected +/tests/**/*.actual +/coverage.* diff --git a/Makefile b/Makefile index bca5444..2d90e2f 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,34 @@ -.PHONY: qa lint cs csf phpstan tests coverage - -all: - @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs - -vendor: composer.json composer.lock - composer install - -qa: lint phpstan cs - -lint: vendor - vendor/bin/linter src tests - -cs: vendor - vendor/bin/codesniffer src tests - -csf: vendor - vendor/bin/codefixer src tests - -phpstan: vendor - vendor/bin/phpstan analyse -l 8 -c phpstan.neon src - -tests: vendor +.PHONY: install +install: + composer update + +.PHONY: qa +qa: phpstan cs + +.PHONY: cs +cs: +ifdef GITHUB_ACTION + vendor/bin/phpcs --standard=ruleset.xml --extensions="php,phpt" --encoding=utf-8 --report=checkstyle -q src tests | cs2pr +else + vendor/bin/phpcs --standard=ruleset.xml --extensions="php,phpt" --encoding=utf-8 --colors -nsp src tests +endif + +.PHONY: csf +csf: + vendor/bin/phpcbf --standard=ruleset.xml --extensions="php,phpt" --encoding=utf-8 --colors -nsp src tests + +.PHONY: phpstan +phpstan: + vendor/bin/phpstan analyse -c phpstan.neon + +.PHONY: tests +tests: vendor/bin/tester -s -p php --colors 1 -C tests/cases -coverage: vendor +.PHONY: coverage +coverage: +ifdef GITHUB_ACTION vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests/cases +else + vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.html --coverage-src ./src tests/cases +endif diff --git a/composer.json b/composer.json index eff2d8a..e8ea07f 100644 --- a/composer.json +++ b/composer.json @@ -21,23 +21,25 @@ } ], "require": { - "php": ">= 8.1" + "php": ">=8.2" }, "require-dev": { - "ninjify/qa": "^0.12", - "ninjify/nunjuck": "^0.3", - "nette/di": "^3.0.0", - "mockery/mockery": "^1.2.0", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-nette": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0" + "contributte/qa": "~0.4.0", + "contributte/phpstan": "~0.2.0", + "contributte/tester": "~0.3.0", + "nette/di": "^3.2.0", + "mockery/mockery": "^1.6.0" }, "autoload": { "psr-4": { "Contributte\\Fio\\": "src" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests" + } + }, "minimum-stability": "dev", "prefer-stable": true, "extra": { @@ -46,6 +48,7 @@ } }, "config": { + "sort-packages": true, "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } diff --git a/phpstan.neon b/phpstan.neon index 37c833f..9871fc1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,10 +1,19 @@ includes: - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - - vendor/phpstan/phpstan-nette/extension.neon - - vendor/phpstan/phpstan-nette/rules.neon - - vendor/phpstan/phpstan-strict-rules/rules.neon + - vendor/contributte/phpstan/phpstan.neon parameters: + level: 9 + phpVersion: 80200 + + scanDirectories: + - src + + fileExtensions: + - php + + paths: + - src + ignoreErrors: # curl_exec returns result thanks to option CURLOPT_RETURNTRANSFER - wtf is that api? - '#^Method Contributte\\Fio\\Http\\HttpClient\:\:sendRequest\(\) should return string but returns string\|true\.$#' @@ -12,5 +21,23 @@ parameters: # Probably bug, LibXMLError does not use Throwable - '#^Parameter \#3 \$previous of class Contributte\\Fio\\Exceptions\\InvalidResponseException constructor expects Throwable\|null, LibXMLError given\.$#' - - '#Property Contributte\\Fio\\(.*)::\$(.*) \(float\) in isset\(\) is not nullable\.#' - - '#Property Contributte\\Fio\\(.*)::\$(.*) \(string\) in isset\(\) is not nullable\.#' + # HttpClient curl_setopt type issues + - '#^Parameter \#3 \$value of function curl_setopt expects non-empty-string, string given\.$#' + - '#^Parameter \#3 \$value of function curl_setopt expects non-empty-string\|null, string given\.$#' + - '#^Parameter \#3 \$value of function curl_setopt expects bool, int given\.$#' + - '#^Offset .uri. might not exist on array\{#' + - '#^Parameter \#1 \$message of class Contributte\\Fio\\Exceptions\\IOException constructor expects string, string\|null given\.$#' + + # SimpleXMLElement property access + - '#^Access to an undefined property iterable&Traversable::\$#' + + # ExportXmlGenerator mixed type issues + - + message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#' + path: src/Utils/ExportXmlGenerator.php + - + message: '#^Parameter \#1 \$qualifiedName of method SimpleXMLElement::addChild\(\) expects string, mixed given\.$#' + path: src/Utils/ExportXmlGenerator.php + - + message: '#^Cannot cast mixed to string\.$#' + path: src/Utils/ExportXmlGenerator.php diff --git a/ruleset.xml b/ruleset.xml index 4d3e9d7..46c64a1 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,18 +1,18 @@ - - + + - - - - - - + + + + + + + + + - - /tests/tmp + + /tests/tmp diff --git a/src/Config.php b/src/Config.php index 5203969..e96d21e 100644 --- a/src/Config.php +++ b/src/Config.php @@ -12,7 +12,7 @@ class Config { /** @var Account[] */ - private $accounts; + private array $accounts; public function addAccount(string $name, Account $account): void { diff --git a/src/Entity/Account/Account.php b/src/Entity/Account/Account.php index 603607e..15f81f9 100644 --- a/src/Entity/Account/Account.php +++ b/src/Entity/Account/Account.php @@ -10,11 +10,9 @@ class Account { - /** @var string */ - private $token; + private string $token; - /** @var string */ - private $accountNum; + private string $accountNum; public function __construct(string $token, string $accountNum) { diff --git a/src/Entity/Transaction/DomesticTransaction.php b/src/Entity/Transaction/DomesticTransaction.php index ceabfa3..bfbc8f8 100644 --- a/src/Entity/Transaction/DomesticTransaction.php +++ b/src/Entity/Transaction/DomesticTransaction.php @@ -14,36 +14,31 @@ final class DomesticTransaction extends Transaction // Standardní public const PAYMENT_TYPE_STANDARD = 431001; + // Zrychlená public const PAYMENT_TYPE_FASTER = 431004; + // Prioritní public const PAYMENT_TYPE_PRIORITY = 431005; + // Příkaz k inkasu public const PAYMENT_TYPE_COLLECTION = 431022; - /** @var int */ - private $paymentType; + private int $paymentType; - /** @var string */ - private $bankCode; + private string $bankCode; - /** @var string */ - private $ks; + private string $ks; - /** @var string */ - private $vs; + private string $vs; - /** @var string */ - private $ss; + private string $ss; - /** @var string */ - private $messageForRecipient; + private string $messageForRecipient; - /** @var string */ - private $comment; + private string $comment; - /** @var int */ - private $paymentReason; + private int $paymentReason; public function setPaymentType(int $paymentType): void { diff --git a/src/Entity/Transaction/Transaction.php b/src/Entity/Transaction/Transaction.php index 1baa032..11af48f 100644 --- a/src/Entity/Transaction/Transaction.php +++ b/src/Entity/Transaction/Transaction.php @@ -17,20 +17,20 @@ abstract class Transaction public const CZK = 'CZK'; public const EURO = 'EUR'; - /** @var string */ - protected $accountFrom; + protected string $accountFrom; - /** @var string */ - protected $currency = self::CZK; + protected string $currency = self::CZK; - /** @var float */ - protected $amount; + protected float $amount; - /** @var string */ - protected $accountTo; + protected string $accountTo; - /** @var string */ - protected $date; + protected string $date; + + /** + * Checks if all mandatory data are set + */ + abstract public function isValid(): bool; public function setAccountFrom(string $accountFrom): void { @@ -86,9 +86,4 @@ public function toArray(): array ]; } - /** - * Checks if all mandatory data are set - */ - abstract public function isValid(): bool; - } diff --git a/src/Entity/Transaction/TransactionList.php b/src/Entity/Transaction/TransactionList.php index fdc248d..16951f3 100644 --- a/src/Entity/Transaction/TransactionList.php +++ b/src/Entity/Transaction/TransactionList.php @@ -13,7 +13,7 @@ class TransactionList implements IteratorAggregate { /** @var Transaction[] */ - protected $transactions = []; + protected array $transactions = []; public function addTransaction(Transaction $transaction): void { diff --git a/src/Exceptions/InvalidResponseException.php b/src/Exceptions/InvalidResponseException.php index 1f56b6d..75d3c73 100644 --- a/src/Exceptions/InvalidResponseException.php +++ b/src/Exceptions/InvalidResponseException.php @@ -10,8 +10,7 @@ class InvalidResponseException extends RuntimeException { - /** @var string|null */ - protected $result; + protected ?string $result = null; public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null, ?string $result = null) { diff --git a/src/FioManager.php b/src/FioManager.php index 5b047e4..06fe4a0 100644 --- a/src/FioManager.php +++ b/src/FioManager.php @@ -11,11 +11,9 @@ class FioManager { - /** @var Config */ - private $config; + private Config $config; - /** @var IHttpClient */ - private $httpClient; + private IHttpClient $httpClient; public function __construct(Config $config, IHttpClient $httpClient) { diff --git a/src/Http/PaymentResponse.php b/src/Http/PaymentResponse.php index a8f5b7f..9395185 100644 --- a/src/Http/PaymentResponse.php +++ b/src/Http/PaymentResponse.php @@ -26,11 +26,9 @@ class PaymentResponse 14 => 'empty file - no transactions in file', ]; - /** @var SimpleXMLElement */ - private $xml; + private SimpleXMLElement $xml; - /** @var string */ - private $pureResult; + private string $pureResult; /** * @throws InvalidResponseException when unexpected XML structure diff --git a/src/Http/Request.php b/src/Http/Request.php index 351be2f..81632c1 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -11,17 +11,13 @@ class Request public const POST = 'POST'; public const GET = 'GET'; - /** @var string */ - private $token; + private string $token; - /** @var string */ - private $fileContents; + private string $fileContents; - /** @var string */ - private $url; + private string $url; - /** @var string */ - private $requestType; + private string $requestType; public function __construct(string $url, string $token, string $requestType = self::GET) { diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 74554a8..855def5 100644 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -20,8 +20,7 @@ class PaymentService extends Service private const URL = 'https://fioapi.fio.cz/v1/rest/import/'; - /** @var TransactionList|null */ - private $transactionList; + private ?TransactionList $transactionList = null; public function __construct(Account $account, IHttpClient $httpClient) { diff --git a/src/Services/Service.php b/src/Services/Service.php index a92c215..a95eefe 100644 --- a/src/Services/Service.php +++ b/src/Services/Service.php @@ -12,11 +12,9 @@ abstract class Service { - /** @var IHttpClient */ - protected $httpClient; + protected IHttpClient $httpClient; - /** @var Account */ - protected $account; + protected Account $account; public function __construct(Account $account, IHttpClient $httpClient) { diff --git a/tests/.coveralls.yml b/tests/.coveralls.yml deleted file mode 100644 index 82764a3..0000000 --- a/tests/.coveralls.yml +++ /dev/null @@ -1,4 +0,0 @@ -# for php-coveralls -service_name: travis-ci -coverage_clover: coverage.xml -json_path: coverage.json diff --git a/tests/.gitignore b/tests/.gitignore deleted file mode 100644 index f0d3402..0000000 --- a/tests/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Folders - recursive -*.expected -*.actual - -# Folders -/tmp - -# Files -/*.log -/*.html diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5595f86..86c92a0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,29 +1,10 @@ load(function (Compiler $compiler): void { $compiler->addExtension('fio', new FioApiExtension()) ->addConfig([ diff --git a/tests/cases/Entity/Transaction/DomesticTransactionTest.phpt b/tests/cases/Entity/Transaction/DomesticTransactionTest.phpt index cc2ba55..8c0efd9 100644 --- a/tests/cases/Entity/Transaction/DomesticTransactionTest.phpt +++ b/tests/cases/Entity/Transaction/DomesticTransactionTest.phpt @@ -1,12 +1,16 @@ setAmount(222.22); $t->setAccountTo('222444666'); @@ -17,7 +21,7 @@ test(function (): void { }); // Missing amount -test(function (): void { +Toolkit::test(function (): void { $t = new DomesticTransaction(); $t->setAccountFrom('111222333444'); $t->setAccountTo('222444666'); @@ -28,7 +32,7 @@ test(function (): void { }); // Missing account to -test(function (): void { +Toolkit::test(function (): void { $t = new DomesticTransaction(); $t->setAccountFrom('111222333444'); $t->setAmount(222.22); @@ -39,7 +43,7 @@ test(function (): void { }); // Missing bank code -test(function (): void { +Toolkit::test(function (): void { $t = new DomesticTransaction(); $t->setAccountFrom('111222333444'); $t->setAmount(222.22); @@ -50,7 +54,7 @@ test(function (): void { }); // Missing date -test(function (): void { +Toolkit::test(function (): void { $t = new DomesticTransaction(); $t->setAccountFrom('111222333444'); $t->setAmount(222.22); @@ -61,7 +65,7 @@ test(function (): void { }); // Valid -test(function (): void { +Toolkit::test(function (): void { $t = new DomesticTransaction(); $t->setAccountFrom('111222333444'); $t->setAmount(222.22); diff --git a/tests/cases/Services/PaymentServiceTest.phpt b/tests/cases/Services/PaymentServiceTest.phpt index c474026..d421edc 100644 --- a/tests/cases/Services/PaymentServiceTest.phpt +++ b/tests/cases/Services/PaymentServiceTest.phpt @@ -1,16 +1,20 @@