diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..70caab9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*.php] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 120 +trim_trailing_whitespace = true + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e85fd86..aac0da5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,20 +1,26 @@ name: CI -on: [push] +on: [ push ] jobs: - build-test: + check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: PHP Composer - uses: php-actions/composer@v6 - with: - php_version: 8.1 - php_extensions: "bcmath" - - name: PHPUnit tests - uses: php-actions/phpunit@v3 - with: - version: 8.5 - php_version: 8.1 + - name: Checkout project + uses: actions/checkout@v4 + + - name: Install dependencies + uses: php-actions/composer@v6 + with: + php_version: 8.1 + php_extensions: "bcmath" + + - name: Check formatting + run: ./vendor/bin/ecs check + + - name: Run tests + uses: php-actions/phpunit@v3 + with: + version: 8.5 + php_version: 8.1 diff --git a/.gitignore b/.gitignore index c981c1b..36fca47 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /vendor composer.lock *.cache -/temp \ No newline at end of file +/temp diff --git a/README.md b/README.md index c85c1a9..c77c1ca 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,11 @@ Dev Docs -------- * [Setup PIN Tan Account in AqBanking (German)](https://www.aquamaniac.de/rdm/projects/aqbanking/wiki/SetupPinTan) + +### Coding standards + +Run the fixer before push. + +```shell +./vendor/bin/ecs --fix +``` diff --git a/composer.json b/composer.json index 3355dfd..2545366 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "require-dev": { "phpunit/phpunit": "^8.5", "mockery/mockery": "*", - "mikey179/vfsstream": "^1.6" + "mikey179/vfsstream": "^1.6", + "symplify/easy-coding-standard": "^12.0" }, "autoload": { "psr-4": { diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..c31a2fe --- /dev/null +++ b/ecs.php @@ -0,0 +1,36 @@ +paths([ + __DIR__ . '/ecs.php', + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $ecsConfig->rules([ + NoUnusedImportsFixer::class, + StrictComparisonFixer::class, + YodaStyleFixer::class, + OrderedClassElementsFixer::class, + NativeFunctionInvocationFixer::class, + ]); + + $ecsConfig->sets([ + SetList::PSR_12, + SetList::ARRAY, + SetList::SPACES, + SetList::DOCBLOCK, + SetList::NAMESPACES, + SetList::COMMENTS, + ]); +}; diff --git a/src/Account.php b/src/Account.php index ae06094..15fbd86 100644 --- a/src/Account.php +++ b/src/Account.php @@ -20,7 +20,6 @@ class Account implements AccountInterface, Arrayable private $accountHolderName; /** - * @param BankCode $bankCode * @param string $accountNumber * @param string $accountHolderName * @return \AqBanking\Account @@ -61,7 +60,7 @@ public function toArray() return [ 'bankCode' => $this->getBankCode()->getString(), 'accountHolderName' => $this->getAccountHolderName(), - 'accountNumber' => $this->getAccountNumber() + 'accountNumber' => $this->getAccountNumber(), ]; } } diff --git a/src/AccountMatcher.php b/src/AccountMatcher.php index 1a3b4e4..b55e2fc 100644 --- a/src/AccountMatcher.php +++ b/src/AccountMatcher.php @@ -2,7 +2,6 @@ namespace AqBanking; -use AqBanking\Command\GetAccountsCommand; use AqBanking\Command\ListAccountsCommand; /** @@ -25,14 +24,13 @@ public function getExistingAccount(Account $account) { foreach ($this->array as $record) { if ( - $account->getBankCode()->getString() == $record[ListAccountsCommand::BANK] && - $account->getAccountNumber() == $record[ListAccountsCommand::NUMBER] + $account->getBankCode()->getString() === $record[ListAccountsCommand::BANK] && + $account->getAccountNumber() === $record[ListAccountsCommand::NUMBER] ) { - return new ExistingAccount($account, $record[ListAccountsCommand::UNIQUE_ID] ); + return new ExistingAccount($account, $record[ListAccountsCommand::UNIQUE_ID]); } } return null; } } - diff --git a/src/Balance.php b/src/Balance.php index 369d6e0..822a10d 100644 --- a/src/Balance.php +++ b/src/Balance.php @@ -64,7 +64,7 @@ public function toArray() 'priceUnit' => 100, 'currency' => $this->getValue()->getCurrency()->getCode(), ], - 'date' => $this->getDate()->format('Y-m-d') + 'date' => $this->getDate()->format('Y-m-d'), ]; } } diff --git a/src/Bank.php b/src/Bank.php index 16d8b07..2d02fd7 100644 --- a/src/Bank.php +++ b/src/Bank.php @@ -20,9 +20,7 @@ class Bank private $hbciVersion; /** - * @param BankCode $bankCode * @param string $hbciUrl - * @param HbciVersion|null $hbciVersion */ public function __construct(BankCode $bankCode, $hbciUrl, HbciVersion $hbciVersion = null) { diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 916841d..916facc 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -4,11 +4,6 @@ abstract class AbstractCommand { - /** - * @var null|ShellCommandExecutor - */ - private $shellCommandExecutor = null; - /** * @var string */ @@ -25,25 +20,15 @@ abstract class AbstractCommand protected $pathToAqHBCIToolBinary = 'aqhbci-tool4'; /** - * @param ShellCommandExecutor $shellCommandExecutor + * @var null|ShellCommandExecutor */ + private $shellCommandExecutor = null; + public function setShellCommandExecutor(ShellCommandExecutor $shellCommandExecutor) { $this->shellCommandExecutor = $shellCommandExecutor; } - /** - * @return ShellCommandExecutor - */ - protected function getShellCommandExecutor() - { - if (null === $this->shellCommandExecutor) { - $this->shellCommandExecutor = new ShellCommandExecutor(); - } - - return $this->shellCommandExecutor; - } - /** * @param string $binaryPath */ @@ -67,4 +52,16 @@ public function setPathToAqHBCIToolBinary($pathToAqHBCIToolBinary) { $this->pathToAqHBCIToolBinary = $pathToAqHBCIToolBinary; } + + /** + * @return ShellCommandExecutor + */ + protected function getShellCommandExecutor() + { + if (null === $this->shellCommandExecutor) { + $this->shellCommandExecutor = new ShellCommandExecutor(); + } + + return $this->shellCommandExecutor; + } } diff --git a/src/Command/AddAccountFlagsCommand.php b/src/Command/AddAccountFlagsCommand.php index 0bd5654..3fc4ec3 100644 --- a/src/Command/AddAccountFlagsCommand.php +++ b/src/Command/AddAccountFlagsCommand.php @@ -2,15 +2,13 @@ namespace AqBanking\Command; -use AqBanking\Command\AddUserCommand\UserAlreadyExistsException; use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; -use AqBanking\Account; use AqBanking\ExistingAccount; class AddAccountFlagsCommand extends AbstractCommand { - const FLAG_PREFER_CAMT_DOWNLOAD = 'preferCamtDownload'; + public const FLAG_PREFER_CAMT_DOWNLOAD = 'preferCamtDownload'; public function execute(ExistingAccount $account, $flags) { diff --git a/src/Command/AddUserCommand.php b/src/Command/AddUserCommand.php index 37cb2be..12b04eb 100644 --- a/src/Command/AddUserCommand.php +++ b/src/Command/AddUserCommand.php @@ -9,10 +9,9 @@ class AddUserCommand extends AbstractCommand { - const RETURN_VAR_USER_ALREADY_EXISTS = 3; + public const RETURN_VAR_USER_ALREADY_EXISTS = 3; /** - * @param User $user * @throws AddUserCommand\UserAlreadyExistsException * @throws ShellCommandExecutor\DefectiveResultException */ diff --git a/src/Command/AddUserCommand/UserAlreadyExistsException.php b/src/Command/AddUserCommand/UserAlreadyExistsException.php index 1005fea..9c4d418 100644 --- a/src/Command/AddUserCommand/UserAlreadyExistsException.php +++ b/src/Command/AddUserCommand/UserAlreadyExistsException.php @@ -3,4 +3,5 @@ namespace AqBanking\Command\AddUserCommand; class UserAlreadyExistsException extends \Exception -{} +{ +} diff --git a/src/Command/AddUserFlagsCommand.php b/src/Command/AddUserFlagsCommand.php index 8fbc11b..c9d799a 100644 --- a/src/Command/AddUserFlagsCommand.php +++ b/src/Command/AddUserFlagsCommand.php @@ -2,7 +2,6 @@ namespace AqBanking\Command; -use AqBanking\Command\AddUserCommand\UserAlreadyExistsException; use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; use AqBanking\ExistingUser; @@ -10,7 +9,7 @@ class AddUserFlagsCommand extends AbstractCommand { - const FLAG_SSL_QUIRK_IGNORE_PREMATURE_CLOSE = 'tlsIgnPrematureClose'; + public const FLAG_SSL_QUIRK_IGNORE_PREMATURE_CLOSE = 'tlsIgnPrematureClose'; /** * @deperacted no longer supported in AqBanking 6 diff --git a/src/Command/CheckAqBankingCommand.php b/src/Command/CheckAqBankingCommand.php index 9199910..b66bbea 100644 --- a/src/Command/CheckAqBankingCommand.php +++ b/src/Command/CheckAqBankingCommand.php @@ -31,13 +31,15 @@ private function assertAqBankingIsAppropriateVersion() if (0 !== $result->getReturnVar()) { throw new AqBankingVersionTooOldException( - 'Required version: ' . $minVersion . ' - present version: unknown'); + 'Required version: ' . $minVersion . ' - present version: unknown' + ); } $versionString = $result->getOutput()[0]; if (version_compare($versionString, $minVersion) < 0) { throw new AqBankingVersionTooOldException( - 'Required version: ' . $minVersion . ' - present version: ' . $versionString); + 'Required version: ' . $minVersion . ' - present version: ' . $versionString + ); } } } diff --git a/src/Command/CheckAqBankingCommand/AqBankingNotRespondingException.php b/src/Command/CheckAqBankingCommand/AqBankingNotRespondingException.php index f04c7f9..a7aa83d 100644 --- a/src/Command/CheckAqBankingCommand/AqBankingNotRespondingException.php +++ b/src/Command/CheckAqBankingCommand/AqBankingNotRespondingException.php @@ -3,4 +3,5 @@ namespace AqBanking\Command\CheckAqBankingCommand; class AqBankingNotRespondingException extends \Exception -{} +{ +} diff --git a/src/Command/CheckAqBankingCommand/AqBankingVersionTooOldException.php b/src/Command/CheckAqBankingCommand/AqBankingVersionTooOldException.php index 92b7993..b52e6fd 100644 --- a/src/Command/CheckAqBankingCommand/AqBankingVersionTooOldException.php +++ b/src/Command/CheckAqBankingCommand/AqBankingVersionTooOldException.php @@ -3,4 +3,5 @@ namespace AqBanking\Command\CheckAqBankingCommand; class AqBankingVersionTooOldException extends \Exception -{} +{ +} diff --git a/src/Command/GetAccSepaCommand.php b/src/Command/GetAccSepaCommand.php index 1bfcd2a..df2ac26 100644 --- a/src/Command/GetAccSepaCommand.php +++ b/src/Command/GetAccSepaCommand.php @@ -2,10 +2,8 @@ namespace AqBanking\Command; -use AqBanking\Command\AddUserCommand\UserAlreadyExistsException; use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; -use AqBanking\Account; use AqBanking\ExistingAccount; use AqBanking\PinFile\PinFile; diff --git a/src/Command/GetAccountsCommand.php b/src/Command/GetAccountsCommand.php index f637b3e..aa9383d 100644 --- a/src/Command/GetAccountsCommand.php +++ b/src/Command/GetAccountsCommand.php @@ -4,14 +4,13 @@ use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; -use AqBanking\PinFile\PinFileInterface as PinFile; use AqBanking\ExistingUser; +use AqBanking\PinFile\PinFileInterface as PinFile; class GetAccountsCommand extends AbstractCommand { /** * @param User $user - * @param PinFile $pinFile * @throws ShellCommandExecutor\DefectiveResultException */ public function execute(ExistingUser $user, PinFile $pinFile) diff --git a/src/Command/GetSysIDCommand.php b/src/Command/GetSysIDCommand.php index e410167..67c7658 100644 --- a/src/Command/GetSysIDCommand.php +++ b/src/Command/GetSysIDCommand.php @@ -4,14 +4,13 @@ use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; -use AqBanking\PinFile\PinFileInterface as PinFile; use AqBanking\ExistingUser; +use AqBanking\PinFile\PinFileInterface as PinFile; class GetSysIDCommand extends AbstractCommand { /** * @param User $user - * @param PinFile $pinFile * @throws ShellCommandExecutor\DefectiveResultException */ public function execute(ExistingUser $user, PinFile $pinFile) diff --git a/src/Command/ListAccountsCommand.php b/src/Command/ListAccountsCommand.php index d8a29da..dad448e 100644 --- a/src/Command/ListAccountsCommand.php +++ b/src/Command/ListAccountsCommand.php @@ -2,18 +2,16 @@ namespace AqBanking\Command; -use AqBanking\Command\AddUserCommand\UserAlreadyExistsException; -use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; -use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; -use AqBanking\User; - class ListAccountsCommand extends AbstractCommand { - const RETURN_VAR_NOT_FOUND = 4; + public const RETURN_VAR_NOT_FOUND = 4; + + public const BANK = 'bank'; + + public const NUMBER = 'number'; + + public const UNIQUE_ID = 'uniqueId'; - const BANK = 'bank'; - const NUMBER = 'number'; - const UNIQUE_ID = 'uniqueId'; /** * @return array */ @@ -26,7 +24,7 @@ public function execute() $result = $this->getShellCommandExecutor()->execute($shellCommand); - if ($result->getReturnVar() !== 0) { + if (0 !== $result->getReturnVar()) { throw new \RuntimeException( 'AqBanking exited with errors: ' . PHP_EOL . implode(PHP_EOL, $result->getErrors()) @@ -34,8 +32,8 @@ public function execute() } $accounts = []; - foreach($result->getOutput() as $line) { - $parsed = sscanf($line, 'Account %d: Bank: %s Account Number: %s SubAccountId: %s Account Type: %s LocalUniqueId: %d' ); + foreach ($result->getOutput() as $line) { + $parsed = sscanf($line, 'Account %d: Bank: %s Account Number: %s SubAccountId: %s Account Type: %s LocalUniqueId: %d'); $accounts[] = [ self::BANK => $parsed[1], self::NUMBER => $parsed[2], diff --git a/src/Command/ListUsersCommand.php b/src/Command/ListUsersCommand.php index 5c8ba41..e86e83b 100644 --- a/src/Command/ListUsersCommand.php +++ b/src/Command/ListUsersCommand.php @@ -2,14 +2,9 @@ namespace AqBanking\Command; -use AqBanking\Command\AddUserCommand\UserAlreadyExistsException; -use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; -use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; -use AqBanking\User; - class ListUsersCommand extends AbstractCommand { - const RETURN_VAR_NOT_FOUND = 4; + public const RETURN_VAR_NOT_FOUND = 4; /** * @return \DOMDocument|null @@ -23,11 +18,11 @@ public function execute() $result = $this->getShellCommandExecutor()->execute($shellCommand); - if ($result->getReturnVar() === 4) { + if (4 === $result->getReturnVar()) { return null; } - if ($result->getReturnVar() !== 0) { + if (0 !== $result->getReturnVar()) { throw new \RuntimeException( 'AqBanking exited with errors: ' . PHP_EOL . implode(PHP_EOL, $result->getErrors()) diff --git a/src/Command/RenderContextFileToXMLCommand.php b/src/Command/RenderContextFileToXMLCommand.php index 2372f8c..8765e24 100644 --- a/src/Command/RenderContextFileToXMLCommand.php +++ b/src/Command/RenderContextFileToXMLCommand.php @@ -7,7 +7,6 @@ class RenderContextFileToXMLCommand extends AbstractCommand { /** - * @param ContextFile $contextFile * @return \DOMDocument * @throws \RuntimeException */ @@ -22,14 +21,14 @@ public function execute(ContextFile $contextFile, bool $returnSimpleXml = false) $result = $this->getShellCommandExecutor()->execute($shellCommand); - if ($result->getReturnVar() !== 0) { + if (0 !== $result->getReturnVar()) { throw new \RuntimeException( 'AqBanking exited with errors: ' . PHP_EOL . implode(PHP_EOL, $result->getErrors()) ); } - if($returnSimpleXml) { + if ($returnSimpleXml) { return new \SimpleXMLElement(implode(PHP_EOL, $result->getOutput())); } diff --git a/src/Command/RequestCommand.php b/src/Command/RequestCommand.php index 5077b4c..cbd948c 100644 --- a/src/Command/RequestCommand.php +++ b/src/Command/RequestCommand.php @@ -25,11 +25,6 @@ class RequestCommand extends AbstractCommand */ private $pinFile; - /** - * @param Account $account - * @param ContextFile $contextFile - * @param PinFile $pinFile - */ public function __construct(Account $account, ContextFile $contextFile, PinFile $pinFile) { $this->account = $account; @@ -38,7 +33,6 @@ public function __construct(Account $account, ContextFile $contextFile, PinFile } /** - * @param \DateTime $fromDate * @throws ShellCommandExecutor\DefectiveResultException */ public function execute(\DateTime $fromDate = null) @@ -59,7 +53,6 @@ public function execute(\DateTime $fromDate = null) } /** - * @param \DateTime $fromDate * @return string */ private function getShellCommand(\DateTime $fromDate = null) diff --git a/src/Command/SepaTransferCommand.php b/src/Command/SepaTransferCommand.php index 5fe6c33..f93e5df 100644 --- a/src/Command/SepaTransferCommand.php +++ b/src/Command/SepaTransferCommand.php @@ -3,14 +3,13 @@ namespace AqBanking\Command; use AqBanking\Account; +use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; +use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; use AqBanking\ContextFile; use AqBanking\PinFile\PinFile; -use AqBanking\Command\AbstractCommand; -use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; -use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; - -class SepaTransferCommand extends AbstractCommand { +class SepaTransferCommand extends AbstractCommand +{ /** * @var Account */ @@ -26,11 +25,6 @@ class SepaTransferCommand extends AbstractCommand { */ private $pinFile; - /** - * @param Account $account - * @param ContextFile $contextFile - * @param PinFile $pinFile - */ public function __construct(Account $account, ContextFile $contextFile, PinFile $pinFile) { $this->account = $account; @@ -38,8 +32,6 @@ public function __construct(Account $account, ContextFile $contextFile, PinFile $this->pinFile = $pinFile; } - - /** * @param string $rname remote name * @param string $riban remote iban @@ -82,7 +74,7 @@ private function getShellCommand(string $rname, string $riban, string $value, st . " --account=" . escapeshellcmd($this->account->getAccountNumber()) . " --ctxfile=" . escapeshellcmd($this->contextFile->getPath()) . " --rname='" . escapeshellcmd($rname) . "'" - . " --riban=" . escapeshellcmd($riban) + . " --riban=" . escapeshellcmd($riban) . " --value=" . escapeshellcmd($value) . " --purpose='" . escapeshellcmd($purpose) . "'" ; diff --git a/src/Command/SetAppropriateITanModeCommand.php b/src/Command/SetAppropriateITanModeCommand.php index d6b1386..abb523e 100644 --- a/src/Command/SetAppropriateITanModeCommand.php +++ b/src/Command/SetAppropriateITanModeCommand.php @@ -40,7 +40,7 @@ private function determineHbciVersionToSet() $requiredHbciVersion = $this->user->getBank()->getHbciVersion(); $highestVersionAvailable = $this->findHighestAvailableHbciVersion($result); - if (!$highestVersionAvailable) { + if (! $highestVersionAvailable) { throw new DefectiveResultException( 'AqBanking could not find any available HBCI version', 0, @@ -63,7 +63,6 @@ private function determineHbciVersionToSet() } /** - * @param Result $result * @return null|HbciVersion */ private function findHighestAvailableHbciVersion(Result $result) @@ -71,9 +70,9 @@ private function findHighestAvailableHbciVersion(Result $result) $highestVersionAvailable = null; foreach ($result->getOutput() as $line) { - $matches = array(); + $matches = []; $regex = '/^- (?P\d+) \(.+\/(V(?P\d+))\/.+\).*\[available( and selected)?\]$/'; - if (!preg_match($regex, $line, $matches)) { + if (! preg_match($regex, $line, $matches)) { continue; } $version = new HbciVersion($matches['version'], $matches['code']); @@ -86,7 +85,6 @@ private function findHighestAvailableHbciVersion(Result $result) } /** - * @param HbciVersion $highestVersionAvailable * @throws DefectiveResultException */ private function setHbciVersion(HbciVersion $highestVersionAvailable) @@ -100,7 +98,7 @@ private function setHbciVersion(HbciVersion $highestVersionAvailable) $result = $this->getShellCommandExecutor()->execute($shellCommand); - if ($result->getReturnVar() !== 0 || count($result->getErrors()) > 0) { + if (0 !== $result->getReturnVar() || \count($result->getErrors()) > 0) { throw new DefectiveResultException( 'Unexpected result on setting the user\'s HBCI version', 0, diff --git a/src/Command/SetITanModeCommand.php b/src/Command/SetITanModeCommand.php index d1ba11b..b5e60ad 100644 --- a/src/Command/SetITanModeCommand.php +++ b/src/Command/SetITanModeCommand.php @@ -2,7 +2,6 @@ namespace AqBanking\Command; -use AqBanking\Command\AddUserCommand\UserAlreadyExistsException; use AqBanking\Command\ShellCommandExecutor\DefectiveResultException; use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; use AqBanking\ExistingUser; diff --git a/src/Command/ShellCommandExecutor.php b/src/Command/ShellCommandExecutor.php index 043ba00..01a528e 100644 --- a/src/Command/ShellCommandExecutor.php +++ b/src/Command/ShellCommandExecutor.php @@ -6,7 +6,7 @@ class ShellCommandExecutor { - const ERROR_REPORTING = 'error'; + public const ERROR_REPORTING = 'error'; public function execute($shellCommand) { @@ -14,12 +14,12 @@ public function execute($shellCommand) ' GWEN_LOGLEVEL=' . self::ERROR_REPORTING . ' AQHBCI_LOGLEVEL=' . self::ERROR_REPORTING . ' LANG=C ' . $shellCommand; - $output = array(); + $output = []; $returnVar = null; $tempFile = tempnam(sys_get_temp_dir(), 'aqb-'); -// FIXME: Make a configurable log file -// file_put_contents('/tmp/aqbanking.log', $shellCommand . PHP_EOL, FILE_APPEND); + // FIXME: Make a configurable log file + // file_put_contents('/tmp/aqbanking.log', $shellCommand . PHP_EOL, FILE_APPEND); exec($shellCommand . ' 2>' . $tempFile, $output, $returnVar); diff --git a/src/Command/ShellCommandExecutor/DefectiveResultException.php b/src/Command/ShellCommandExecutor/DefectiveResultException.php index 3cee403..f89b846 100644 --- a/src/Command/ShellCommandExecutor/DefectiveResultException.php +++ b/src/Command/ShellCommandExecutor/DefectiveResultException.php @@ -16,10 +16,13 @@ class DefectiveResultException extends \Exception public function __construct($message = '', $code = 0, \Exception $previous = null, Result $result = null, $shellCommand = '') { - parent::__construct($message . + parent::__construct( + $message . " - Command: " . $shellCommand . " - Errors: " . implode(PHP_EOL, $result->getErrors()), - $code, $previous); + $code, + $previous + ); $this->result = $result; $this->shellCommand = $shellCommand; diff --git a/src/Command/ShellCommandExecutor/Result.php b/src/Command/ShellCommandExecutor/Result.php index 7952b0f..c76b741 100644 --- a/src/Command/ShellCommandExecutor/Result.php +++ b/src/Command/ShellCommandExecutor/Result.php @@ -20,8 +20,6 @@ class Result private $returnVar; /** - * @param array $output - * @param array $errors * @param int $returnVar */ public function __construct(array $output, array $errors, $returnVar) diff --git a/src/Command/ShellCommandExecutor/ResultAnalyzer.php b/src/Command/ShellCommandExecutor/ResultAnalyzer.php index 6c763cf..9ace097 100644 --- a/src/Command/ShellCommandExecutor/ResultAnalyzer.php +++ b/src/Command/ShellCommandExecutor/ResultAnalyzer.php @@ -4,7 +4,7 @@ class ResultAnalyzer { - private $expectedOutputRegexes = array( + private $expectedOutputRegexes = [ '/Automatically accepting valid new certificate/', '/Automatically accepting certificate/', '/The TLS connection was non-properly terminated./', // it usually automatically restarts, so no error @@ -38,16 +38,15 @@ class ResultAnalyzer '/There is no old settings folder, need initial setup/', '/Account is new, adding/', '/^ .*$/', // everything starting with a space belongs to a previous message and is not an error (hopefully) - '/Selecting PAIN format.*$/' - ); + '/Selecting PAIN format.*$/', + ]; /** - * @param Result $result * @return bool */ public function isDefectiveResult(Result $result) { - if ($result->getReturnVar() !== 0) { + if (0 !== $result->getReturnVar()) { return true; } if ($error = $this->resultHasErrors($result)) { @@ -58,7 +57,7 @@ public function isDefectiveResult(Result $result) private function resultHasErrors(Result $result) { - if (count($result->getErrors()) == 1 && preg_match('/accepting valid new certificate/', $result->getErrors()[0])) { + if (1 === \count($result->getErrors()) && preg_match('/accepting valid new certificate/', $result->getErrors()[0])) { // When calling getsysid with wrong PIN, we don't get any error message. // The only significant aspect of the error is that the output is just one line with // "accepting valid new certificate" diff --git a/src/ContentXmlRenderer/MoneyElementRenderer.php b/src/ContentXmlRenderer/MoneyElementRenderer.php index d2e932a..cb92939 100644 --- a/src/ContentXmlRenderer/MoneyElementRenderer.php +++ b/src/ContentXmlRenderer/MoneyElementRenderer.php @@ -17,12 +17,12 @@ class MoneyElementRenderer */ public function render($value, $currencyString) { - if ($currencyString == '') { + if ('' === $currencyString) { $currencyString = 'EUR'; } $currency = new Currency($currencyString); - if (false === (new ISOCurrencies())->contains($currency)){ + if (false === (new ISOCurrencies())->contains($currency)) { throw new RuntimeException("Unknown currency input '$currencyString'"); } @@ -32,16 +32,20 @@ public function render($value, $currencyString) /** * @see https://github.com/janunger/aqbanking-php/issues/1 * + * @FIXME You can't rely on floating point numbers. Use bcmath instead. + * see https://0.30000000000000004.com/ + * php -r "var_dump(.1 + .2);" // float(0.30000000000000004) + * * @param string $value * @throws \AqBanking\RuntimeException * @return int */ private function normalizeAmount($value) { - list ($amount, $divisor) = $this->extractAmountAndDivisorAsString($value); + list($amount, $divisor) = $this->extractAmountAndDivisorAsString($value); - $multiplier = 100/(int)$divisor; - $normalizedAmount = (int)$amount * $multiplier; + $multiplier = 100 / (int) $divisor; + $normalizedAmount = (int) $amount * $multiplier; if ($this->isNormalizedValueBiassed($normalizedAmount)) { throw new RuntimeException( @@ -49,29 +53,28 @@ private function normalizeAmount($value) ); } - return (int)$normalizedAmount; + return (int) $normalizedAmount; } /** - * @param $amountString * @return array * @throws \AqBanking\RuntimeException */ private function extractAmountAndDivisorAsString($amountString) { - $matches = array(); + $matches = []; if (preg_match('/^(?P(-){0,1}\d+)\/(?P1(0)*)$/', $amountString, $matches)) { $amount = $matches['amount']; $divisor = $matches['divisor']; - return array($amount, $divisor); + return [$amount, $divisor]; } - $matches = array(); + $matches = []; if (preg_match('/^(?P(-){0,1}\d+)$/', $amountString, $matches)) { $amount = $matches['amount']; - return array($amount, '1'); + return [$amount, '1']; } throw new RuntimeException("Unexpected amount input '$amountString'"); @@ -83,6 +86,6 @@ private function extractAmountAndDivisorAsString($amountString) */ private function isNormalizedValueBiassed($normalizedAmount) { - return $normalizedAmount != (int)$normalizedAmount; + return 0.00 !== fmod($normalizedAmount, 1); } } diff --git a/src/ContextXmlRenderer.php b/src/ContextXmlRenderer.php index 1072df8..a38ac7d 100644 --- a/src/ContextXmlRenderer.php +++ b/src/ContextXmlRenderer.php @@ -3,7 +3,6 @@ namespace AqBanking; use AqBanking\ContentXmlRenderer\MoneyElementRenderer; -use Money\Currency; use Money\Money; class ContextXmlRenderer @@ -36,7 +35,7 @@ public function __construct(\DOMDocument $domDocument) public function getTransactions() { $transactionNodes = $this->domDocument->getElementsByTagName('transaction'); - $transactions = array(); + $transactions = []; foreach ($transactionNodes as $transactionNode) { $localBankCode = $this->renderMultiLineElement( @@ -96,7 +95,7 @@ public function getTransactions() public function getBalances() { $balanceNodes = $this->domDocument->getElementsByTagName('balance'); - $balances = array(); + $balances = []; /** * @var DOMElement $balanceNode @@ -113,13 +112,12 @@ public function getBalances() } /** - * @param \DOMNodeList $nodes * @throws \RuntimeException * @return string */ private function renderMultiLineElement(\DOMNodeList $nodes) { - $lines = array(); + $lines = []; foreach ($nodes as $node) { $line = trim($node->nodeValue); if (false !== strpos($line, '|')) { @@ -132,14 +130,12 @@ private function renderMultiLineElement(\DOMNodeList $nodes) } /** - * @param \DOMNode $node - * @param \DOMNode $node * @throws \RuntimeException * @return \DateTime */ private function renderDateElement(\DOMNode $node = null) { - if(!$node) { + if (! $node) { return null; } @@ -154,7 +150,6 @@ private function renderDateElement(\DOMNode $node = null) } /** - * @param \DOMNode $node * @return Money * @throws \Exception */ @@ -168,7 +163,6 @@ private function renderMoneyElement(\DOMNode $node) } /** - * @param \DOMNodeList $valueNodes * @return string */ private function renderSimpleTextElement(\DOMNodeList $valueNodes) diff --git a/src/ExistingAccount.php b/src/ExistingAccount.php index 3be26e5..a042728 100644 --- a/src/ExistingAccount.php +++ b/src/ExistingAccount.php @@ -19,13 +19,9 @@ class ExistingAccount */ private $uniqueAccountId; - /** - * @param Account $account - * @param int $uniqueAccountId - */ public function __construct(Account $account, int $uniqueAccountId) { - $this->user= $account; + $this->user = $account; $this->uniqueAccountId = $uniqueAccountId; } diff --git a/src/ExistingUser.php b/src/ExistingUser.php index a424dc9..39ded3a 100644 --- a/src/ExistingUser.php +++ b/src/ExistingUser.php @@ -19,14 +19,9 @@ class ExistingUser */ private $uniqueUserId; - /** - * @param string $userId - * @param string $userName - * @param Bank $bank - */ public function __construct(User $user, int $uniqueUserId) { - $this->user= $user; + $this->user = $user; $this->uniqueUserId = $uniqueUserId; } diff --git a/src/HbciVersion.php b/src/HbciVersion.php index a1346dc..73b614a 100644 --- a/src/HbciVersion.php +++ b/src/HbciVersion.php @@ -25,7 +25,6 @@ public function __construct($versionNumber, $methodCode = null) } /** - * @param HbciVersion $hbciVersion * @return bool */ public function isHigherThan(HbciVersion $hbciVersion = null) diff --git a/src/PinFile/PinFileCreator.php b/src/PinFile/PinFileCreator.php index 9daddef..c86a731 100644 --- a/src/PinFile/PinFileCreator.php +++ b/src/PinFile/PinFileCreator.php @@ -18,7 +18,6 @@ public function __construct($pinFileDir) /** * @param string $pin - * @param User $user * @return PinFileInterface */ public function createFile($pin, User $user) @@ -46,10 +45,10 @@ public function createFile($pin, User $user) */ private function assertIsWritableDir($pinFileDir) { - if (!is_dir($pinFileDir)) { + if (! is_dir($pinFileDir)) { throw new \InvalidArgumentException("PIN file dir '$pinFileDir' is not a directory"); } - if (!is_writable($pinFileDir)) { + if (! is_writable($pinFileDir)) { throw new \InvalidArgumentException("PIN file dir '$pinFileDir' is not writable"); } } @@ -63,8 +62,7 @@ private function assertIsWritableDir($pinFileDir) private function createFileContent($pin, $userId, $bankCodeString) { // The comments and line breaks seem to be mandatory for AqBanking to parse the file - return - '# This is a PIN file to be used with AqBanking' . PHP_EOL + return '# This is a PIN file to be used with AqBanking' . PHP_EOL . '# Please insert the PINs/passwords for the users below' . PHP_EOL . PHP_EOL . '# User "' . $userId . '" at "' . $bankCodeString . '"' . PHP_EOL diff --git a/src/RuntimeException.php b/src/RuntimeException.php index f1f476c..1141a25 100644 --- a/src/RuntimeException.php +++ b/src/RuntimeException.php @@ -3,4 +3,5 @@ namespace AqBanking; class RuntimeException extends \RuntimeException -{} +{ +} diff --git a/src/Transaction.php b/src/Transaction.php index 0c23943..bfb5ec3 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -156,11 +156,11 @@ public function toArray() 'value' => [ 'amount' => $this->getValue()->getAmount(), 'currency' => $this->getValue()->getCurrency()->getName(), - 'priceUnit' => 100 + 'priceUnit' => 100, ], 'valutaDate' => $this->getValutaDate() ? $this->getValutaDate()->format('Y-m-d') : null, 'primaNota' => $this->getPrimaNota(), - 'customerReference' => $this->getCustomerReference() + 'customerReference' => $this->getCustomerReference(), ]; } } diff --git a/src/User.php b/src/User.php index 5057afd..c664683 100644 --- a/src/User.php +++ b/src/User.php @@ -22,7 +22,6 @@ class User /** * @param string $userId * @param string $userName - * @param Bank $bank */ public function __construct($userId, $userName, Bank $bank) { diff --git a/src/UserMatcher.php b/src/UserMatcher.php index c4f9e51..d4d0d65 100644 --- a/src/UserMatcher.php +++ b/src/UserMatcher.php @@ -16,14 +16,14 @@ class UserMatcher public function __construct(\DOMDocument $domDocument = null) { $this->domDocument = $domDocument; - if ($domDocument !== null) { + if (null !== $domDocument) { $this->xPath = new \DOMXPath($domDocument); } } public function getExistingUser(User $user) { - if ($this->domDocument === null) { + if (null === $this->domDocument) { return null; } @@ -37,9 +37,9 @@ public function getExistingUser(User $user) $uniqueId = $userNode->getElementsByTagName('userUniqueId')[0]->nodeValue; if ( - $user->getUserName() == $userName && - $user->getUserId() == $userId && - $user->getBank()->getBankCode()->getString() == $bankCode + $user->getUserName() === $userName && + $user->getUserId() === $userId && + $user->getBank()->getBankCode()->getString() === $bankCode ) { return new ExistingUser($user, $uniqueId); } @@ -48,4 +48,3 @@ public function getExistingUser(User $user) return null; } } - diff --git a/tests/Command/AddUserCommandTest.php b/tests/Command/AddUserCommandTest.php index 820e00c..8f908c6 100644 --- a/tests/Command/AddUserCommandTest.php +++ b/tests/Command/AddUserCommandTest.php @@ -3,10 +3,10 @@ namespace Tests\Command; use AqBanking\Bank; -use AqBanking\User; use AqBanking\BankCode; use AqBanking\Command\AddUserCommand; use AqBanking\Command\ShellCommandExecutor\Result; +use AqBanking\User; class AddUserCommandTest extends ShellCommandTestCase { @@ -36,7 +36,7 @@ public function testCanAddAqBankingUser() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result(array(), array(), 0)); + ->andReturn(new Result([], [], 0)); $sut = new AddUserCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -69,7 +69,7 @@ public function testThrowsExceptionIfUserAlreadyExists() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result(array(), array(), AddUserCommand::RETURN_VAR_USER_ALREADY_EXISTS)); + ->andReturn(new Result([], [], AddUserCommand::RETURN_VAR_USER_ALREADY_EXISTS)); $sut = new AddUserCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -100,7 +100,7 @@ public function testThrowsExceptionOnUnexpectedResult() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result(array(), array(), 127)); + ->andReturn(new Result([], [], 127)); $sut = new AddUserCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); diff --git a/tests/Command/CheckAqBankingCommandTest.php b/tests/Command/CheckAqBankingCommandTest.php index 10ba300..f43b4f7 100644 --- a/tests/Command/CheckAqBankingCommandTest.php +++ b/tests/Command/CheckAqBankingCommandTest.php @@ -2,9 +2,9 @@ namespace Tests\Command; -use PHPUnit\Framework\TestCase; use AqBanking\Command\CheckAqBankingCommand; use AqBanking\Command\ShellCommandExecutor\Result; +use PHPUnit\Framework\TestCase; class CheckAqBankingCommandTest extends TestCase { @@ -14,11 +14,11 @@ public function testCanTellIfAqBankingIsInstalled() $shellCommandExecutorMock ->shouldReceive('execute') ->with('aqbanking-cli --help') - ->andReturn(new Result(array(), array(), 0)); + ->andReturn(new Result([], [], 0)); $shellCommandExecutorMock ->shouldReceive('execute') ->with('aqbanking-config --vstring') - ->andReturn(new Result(array('5.0.24'), array(), 0)); + ->andReturn(new Result(['5.0.24'], [], 0)); $sut = new CheckAqBankingCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -34,7 +34,7 @@ public function testCanTellIfAqBankingIsNotInstalled() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with('aqbanking-cli --help') - ->andReturn(new Result(array(), array(), 127)); + ->andReturn(new Result([], [], 127)); $sut = new CheckAqBankingCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -48,11 +48,11 @@ public function testCanHandleVeryOldAqBankingVersionWithoutAqBankingConfig() $shellCommandExecutorMock ->shouldReceive('execute') ->with('aqbanking-cli --help') - ->andReturn(new Result(array(), array(), 0)); + ->andReturn(new Result([], [], 0)); $shellCommandExecutorMock ->shouldReceive('execute') ->with('aqbanking-config --vstring') - ->andReturn(new Result(array(), array(), 127)); + ->andReturn(new Result([], [], 127)); $sut = new CheckAqBankingCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -66,11 +66,11 @@ public function testCanTellIfAqBankingVersionIsTooOld() $shellCommandExecutorMock ->shouldReceive('execute') ->with('aqbanking-cli --help') - ->andReturn(new Result(array(), array(), 0)); + ->andReturn(new Result([], [], 0)); $shellCommandExecutorMock ->shouldReceive('execute') ->with('aqbanking-config --vstring') - ->andReturn(new Result(array('5.0.23'), array(), 0)); + ->andReturn(new Result(['5.0.23'], [], 0)); $sut = new CheckAqBankingCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); diff --git a/tests/Command/GetSysIDCommandTest.php b/tests/Command/GetSysIDCommandTest.php index c418205..b6967a2 100644 --- a/tests/Command/GetSysIDCommandTest.php +++ b/tests/Command/GetSysIDCommandTest.php @@ -3,12 +3,12 @@ namespace Tests\Command; use AqBanking\Bank; -use AqBanking\User; use AqBanking\BankCode; -use AqBanking\ExistingUser; -use AqBanking\PinFile\PinFile; use AqBanking\Command\GetSysIDCommand; use AqBanking\Command\ShellCommandExecutor\Result; +use AqBanking\ExistingUser; +use AqBanking\PinFile\PinFile; +use AqBanking\User; class GetSysIDCommandTest extends ShellCommandTestCase { @@ -40,7 +40,7 @@ public function testPollsSysID() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result(array(), array(), 0)); + ->andReturn(new Result([], [], 0)); $sut = new GetSysIDCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -79,7 +79,7 @@ public function testThrowsExceptionOnUnexpectedResult() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result(array(), array(), 1)); + ->andReturn(new Result([], [], 1)); $sut = new GetSysIDCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); diff --git a/tests/Command/RenderContextFileToXMLCommandTest.php b/tests/Command/RenderContextFileToXMLCommandTest.php index db0226c..2dc16f8 100644 --- a/tests/Command/RenderContextFileToXMLCommandTest.php +++ b/tests/Command/RenderContextFileToXMLCommandTest.php @@ -2,10 +2,10 @@ namespace Tests\Command; +use AqBanking\Command\RenderContextFileToXMLCommand; +use AqBanking\Command\ShellCommandExecutor\Result; use AqBanking\ContextFile; use PHPUnit\Framework\TestCase; -use AqBanking\Command\ShellCommandExecutor\Result; -use AqBanking\Command\RenderContextFileToXMLCommand; class RenderContextFileToXMLCommandTest extends TestCase { @@ -21,25 +21,23 @@ public function testCanIssueCorrectRenderCommand() . ' export' . ' --ctxfile=' . $contextFile->getPath() . ' --exporter=xmldb'; - $output = array( + $output = [ '', '', - '' - ); + '', + ]; $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result($output, array(), 0)); + ->andReturn(new Result($output, [], 0)); $expectedXmlString = implode(PHP_EOL, $output); - $sut = new RenderContextFileToXMLCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); $result = $sut->execute($contextFile); - $this->assertInstanceOf('DOMDocument', $result); $this->assertXmlStringEqualsXmlString($expectedXmlString, $result->saveXML()); } @@ -49,7 +47,7 @@ public function testCanHandleUnexpectedOutput() $shellCommandExecutorMock = \Mockery::mock('AqBanking\Command\ShellCommandExecutor'); $shellCommandExecutorMock ->shouldReceive('execute')->once() - ->andReturn(new Result(array(), array(), 1)); + ->andReturn(new Result([], [], 1)); $sut = new RenderContextFileToXMLCommand(); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -72,7 +70,8 @@ public function testCanRenderSimpleXML() [file_get_contents('./tests/fixtures/test_context_file_transactions_with_type_transfer.xml')], [], 0 - )); + ) + ); $simpleXML = $sut->execute( new ContextFile('/path/to/some/context/file.ctx'), @@ -81,62 +80,62 @@ public function testCanRenderSimpleXML() $this->assertEquals( 'DE33123456780000000000', - (string)$simpleXML->accountInfoList->accountInfo->iban->value + (string) $simpleXML->accountInfoList->accountInfo->iban->value ); $this->assertEquals( 'ASDFFFWWAA', - (string)$simpleXML->accountInfoList->accountInfo->bic->value + (string) $simpleXML->accountInfoList->accountInfo->bic->value ); $this->assertEquals( 'HARALD MUSTERMANN', - (string)$simpleXML->accountInfoList->accountInfo->owner->value + (string) $simpleXML->accountInfoList->accountInfo->owner->value ); $this->assertEquals( 'DE15453384569356645534', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->remoteIban->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->remoteIban->value ); $this->assertEquals( 'WARENHAUS GMBH', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->remoteName->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->remoteName->value ); $this->assertEquals( '2174/100:EUR', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->value->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->value->value ); $this->assertEquals( '0', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->executionDay->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->executionDay->value ); $this->assertEquals( '20220106', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->date->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->date->value ); $this->assertEquals( 'Rechnung', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->purpose->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->purpose->value ); $this->assertEquals( 'transfer', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->type->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->type->value ); $this->assertEquals( 'pending', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->status->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->status->value ); $this->assertEquals( '2407', - (string)$simpleXML->accountInfoList->accountInfo->transactionList->transaction->uniqueId->value + (string) $simpleXML->accountInfoList->accountInfo->transactionList->transaction->uniqueId->value ); } } diff --git a/tests/Command/RequestCommandTest.php b/tests/Command/RequestCommandTest.php index 54fcb32..8e0b38f 100644 --- a/tests/Command/RequestCommandTest.php +++ b/tests/Command/RequestCommandTest.php @@ -4,9 +4,9 @@ use AqBanking\Account; use AqBanking\BankCode; -use AqBanking\ContextFile; use AqBanking\Command\RequestCommand; use AqBanking\Command\ShellCommandExecutor\Result; +use AqBanking\ContextFile; class RequestCommandTest extends ShellCommandTestCase { @@ -39,7 +39,7 @@ public function testCanExecute() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result(array(), array(), 0)); + ->andReturn(new Result([], [], 0)); $sut = new RequestCommand($account, $contextFile, $pinFileMock); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -81,7 +81,7 @@ public function testCanExecuteWithFromDate() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result(array(), array(), 0)); + ->andReturn(new Result([], [], 0)); $sut = new RequestCommand($account, $contextFile, $pinFileMock); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -107,7 +107,7 @@ public function testThrowsExceptionOnUnexpectedResult() $shellCommandExecutorMock = $this->getShellCommandExecutorMock(); $shellCommandExecutorMock ->shouldReceive('execute')->once() - ->andReturn(new Result(array(), array('some unexpected output'), 0)); + ->andReturn(new Result([], ['some unexpected output'], 0)); $sut = new RequestCommand($account, $contextFile, $pinFileMock); $sut->setShellCommandExecutor($shellCommandExecutorMock); diff --git a/tests/Command/SepaTransferCommandTest.php b/tests/Command/SepaTransferCommandTest.php index e9e480b..f15ca84 100644 --- a/tests/Command/SepaTransferCommandTest.php +++ b/tests/Command/SepaTransferCommandTest.php @@ -4,10 +4,9 @@ use AqBanking\Account; use AqBanking\BankCode; -use AqBanking\ContextFile; use AqBanking\Command\SepaTransferCommand; -use Tests\Command\ShellCommandTestCase; use AqBanking\Command\ShellCommandExecutor\Result; +use AqBanking\ContextFile; class SepaTransferCommandTest extends ShellCommandTestCase { @@ -48,7 +47,7 @@ public function testCanExecute() $shellCommandExecutorMock ->shouldReceive('execute')->once() ->with($expectedCommand) - ->andReturn(new Result(array(), array(), 0)); + ->andReturn(new Result([], [], 0)); $sut = new SepaTransferCommand($account, $contextFile, $pinFileMock); $sut->setShellCommandExecutor($shellCommandExecutorMock); @@ -59,10 +58,10 @@ public function testCanExecute() $purpose ); $this->assertTrue(true); - } - public function testAcceptsValidOutput() { + public function testAcceptsValidOutput() + { $accountNumber = '12345678'; $bankCodeString = '23456789'; $bankCode = new BankCode($bankCodeString); @@ -77,17 +76,15 @@ public function testAcceptsValidOutput() { $shellCommandExecutorMock = $this->getShellCommandExecutorMock(); $shellCommandExecutorMock ->shouldReceive('execute')->once() - ->andReturn(new Result(array(), array('3:2022/01/06 05-26-00:aqhbci(42):jobtransferbase.c: 1036: Selecting PAIN format [urn:iso:std:iso:20022:tech:xsd:pain.001.001.03]'), 0)); + ->andReturn(new Result([], ['3:2022/01/06 05-26-00:aqhbci(42):jobtransferbase.c: 1036: Selecting PAIN format [urn:iso:std:iso:20022:tech:xsd:pain.001.001.03]'], 0)); $sut = new SepaTransferCommand($account, $contextFile, $pinFileMock); $sut->setShellCommandExecutor($shellCommandExecutorMock); // No exception has been thrown for a valid error output by aqbanking $this->assertTrue(true); - } - /** * @param string $pathToPinFile * @return \Mockery\MockInterface @@ -101,4 +98,4 @@ private function getPinFileMock($pathToPinFile) return $pinFileMock; } -} \ No newline at end of file +} diff --git a/tests/Command/ShellCommandExecutor/ResultAnalyzerTest.php b/tests/Command/ShellCommandExecutor/ResultAnalyzerTest.php index 5adeadb..c1c0ab4 100644 --- a/tests/Command/ShellCommandExecutor/ResultAnalyzerTest.php +++ b/tests/Command/ShellCommandExecutor/ResultAnalyzerTest.php @@ -2,15 +2,15 @@ namespace Tests\Command\ShellCommandExecutor; -use PHPUnit\Framework\TestCase; use AqBanking\Command\ShellCommandExecutor\Result; use AqBanking\Command\ShellCommandExecutor\ResultAnalyzer; +use PHPUnit\Framework\TestCase; class ResultAnalyzerTest extends TestCase { public function testEmptyResultIsNoError() { - $result = new Result(array(), array(), 0); + $result = new Result([], [], 0); $sut = new ResultAnalyzer(); @@ -19,7 +19,7 @@ public function testEmptyResultIsNoError() public function testRecognizesErrorByResultVar() { - $result = new Result(array(), array(), 1); + $result = new Result([], [], 1); $sut = new ResultAnalyzer(); @@ -28,15 +28,15 @@ public function testRecognizesErrorByResultVar() public function testCanTellCorrectPollResult() { - $errors = array( + $errors = [ '5:2013/07/22 11-32-32:aqbanking(39873):abgui.c: 182: Automatically accepting valid new certificate [40:BD:81:8B:76:27:1A:58:5C:B7:68:46:1E:CB:F2:FD]', '5:2013/07/22 11-32-33:aqbanking(39873):abgui.c: 182: Automatically accepting valid new certificate [40:BD:81:8B:76:27:1A:58:5C:B7:68:46:1E:CB:F2:FD]', '5:2013/07/22 11-32-33:aqbanking(39873):abgui.c: 182: Automatically accepting valid new certificate [40:BD:81:8B:76:27:1A:58:5C:B7:68:46:1E:CB:F2:FD]', '5:2013/07/22 11-32-33:aqbanking(39873):abgui.c: 182: Automatically accepting valid new certificate [40:BD:81:8B:76:27:1A:58:5C:B7:68:46:1E:CB:F2:FD]', '5:2013/07/22 11-32-34:aqbanking(39873):abgui.c: 182: Automatically accepting valid new certificate [40:BD:81:8B:76:27:1A:58:5C:B7:68:46:1E:CB:F2:FD]', - '5:2013/07/22 11-32-34:aqbanking(39873):abgui.c: 182: Automatically accepting valid new certificate [40:BD:81:8B:76:27:1A:58:5C:B7:68:46:1E:CB:F2:FD]' - ); - $result = new Result(array(), $errors, 0); + '5:2013/07/22 11-32-34:aqbanking(39873):abgui.c: 182: Automatically accepting valid new certificate [40:BD:81:8B:76:27:1A:58:5C:B7:68:46:1E:CB:F2:FD]', + ]; + $result = new Result([], $errors, 0); $sut = new ResultAnalyzer(); @@ -45,13 +45,13 @@ public function testCanTellCorrectPollResult() public function testCanTellDefectivePollResult() { - $errors = array( + $errors = [ '5:2013/07/22 11-31-44:aqbanking(39859):abgui.c: 182: Automatically accepting valid new certificate [40:BD:81:8B:76:27:1A:58:5C:B7:68:46:1E:CB:F2:FD]', '3:2013/07/22 11-31-44:aqhbci(39859):outbox.c: 1390: Error performing queue (-2)', '5:2013/07/22 11-31-44:aqbanking(39859):./banking_online.c: 119: Error executing backend\'s queue', - '4:2013/07/22 11-31-44:aqbanking(39859):./banking_online.c: 137: Not a single job successfully executed' - ); - $result = new Result(array(), $errors, 0); + '4:2013/07/22 11-31-44:aqbanking(39859):./banking_online.c: 137: Not a single job successfully executed', + ]; + $result = new Result([], $errors, 0); $sut = new ResultAnalyzer(); diff --git a/tests/Command/ShellCommandExecutorTest.php b/tests/Command/ShellCommandExecutorTest.php index 0705380..104bd1d 100644 --- a/tests/Command/ShellCommandExecutorTest.php +++ b/tests/Command/ShellCommandExecutorTest.php @@ -2,8 +2,8 @@ namespace Tests\Command; -use PHPUnit\Framework\TestCase; use AqBanking\Command\ShellCommandExecutor; +use PHPUnit\Framework\TestCase; class ShellCommandExecutorTest extends TestCase { @@ -13,8 +13,8 @@ public function testCanExecuteCommand() $result = $sut->execute('echo "whatever"'); - $this->assertEquals(array("whatever"), $result->getOutput()); - $this->assertEquals(array(), $result->getErrors()); + $this->assertEquals(["whatever"], $result->getOutput()); + $this->assertEquals([], $result->getErrors()); $this->assertEquals(0, $result->getReturnVar()); } @@ -24,8 +24,8 @@ public function testCanTellAboutErrors() $result = $sut->execute("any-unknown-command"); - $this->assertEquals(array(), $result->getOutput()); - $this->assertNotEquals(0, count($result->getErrors())); + $this->assertEquals([], $result->getOutput()); + $this->assertNotEquals(0, \count($result->getErrors())); $this->assertNotEquals(0, $result->getReturnVar()); } } diff --git a/tests/ContentXmlRenderer/MoneyElementRendererTest.php b/tests/ContentXmlRenderer/MoneyElementRendererTest.php index 47d521b..6564d9c 100644 --- a/tests/ContentXmlRenderer/MoneyElementRendererTest.php +++ b/tests/ContentXmlRenderer/MoneyElementRendererTest.php @@ -2,9 +2,9 @@ namespace Tests\ContentXmlRenderer; +use AqBanking\ContentXmlRenderer\MoneyElementRenderer; use Money\Money; use PHPUnit\Framework\TestCase; -use AqBanking\ContentXmlRenderer\MoneyElementRenderer; class MoneyElementRendererTest extends TestCase { diff --git a/tests/ContextXmlRendererTest.php b/tests/ContextXmlRendererTest.php index 7b15186..4ff171f 100644 --- a/tests/ContextXmlRendererTest.php +++ b/tests/ContextXmlRendererTest.php @@ -2,12 +2,12 @@ namespace Tests; -use Money\Money; use AqBanking\Account; use AqBanking\BankCode; +use AqBanking\ContextXmlRenderer; use AqBanking\Transaction; +use Money\Money; use PHPUnit\Framework\TestCase; -use AqBanking\ContextXmlRenderer; class ContextXmlRendererTest extends TestCase { @@ -25,7 +25,7 @@ public function can_render_transfers() $sut = new ContextXmlRenderer($domDocument); $localAccount = new Account(new BankCode('12345678'), '404072100', 'HARALD MUSTERMANN'); - $expectedTransactions = array( + $expectedTransactions = [ new Transaction( $localAccount, new Account(new BankCode(''), '', "WARENHAUS GMBH"), @@ -36,7 +36,7 @@ public function can_render_transfers() Money::EUR(2174), '', '' - )); + )]; $this->assertEquals($expectedTransactions, $sut->getTransactions()); } @@ -55,7 +55,7 @@ public function can_render_transactions() $sut = new ContextXmlRenderer($domDocument); $localAccount = new Account(new BankCode('32151229'), '12112345'); - $expectedTransactions = array( + $expectedTransactions = [ new Transaction( $localAccount, new Account(new BankCode('MALADE51KOB'), 'DE62570501200000012345', 'Sehr sehr langer Kontoinhab'), @@ -66,10 +66,9 @@ public function can_render_transactions() Money::EUR(-1111), '97186', 'KREW+' - )); + )]; $this->assertEquals($expectedTransactions, $sut->getTransactions()); - } /** diff --git a/tests/PinFileCreatorTest.php b/tests/PinFileCreatorTest.php index d97205f..fc5a321 100644 --- a/tests/PinFileCreatorTest.php +++ b/tests/PinFileCreatorTest.php @@ -3,11 +3,11 @@ namespace Tests; use AqBanking\Bank; -use AqBanking\User; use AqBanking\BankCode; +use AqBanking\PinFile\PinFileCreator; +use AqBanking\User; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; -use AqBanking\PinFile\PinFileCreator; class PinFileCreatorTest extends TestCase { diff --git a/tests/TransactionTest.php b/tests/TransactionTest.php index ac800dc..491ae0b 100644 --- a/tests/TransactionTest.php +++ b/tests/TransactionTest.php @@ -2,11 +2,11 @@ namespace Tests; -use Money\Money; -use Money\Currency; use AqBanking\Account; use AqBanking\BankCode; use AqBanking\Transaction; +use Money\Currency; +use Money\Money; use PHPUnit\Framework\TestCase; class TransactionTest extends TestCase