Skip to content

Commit

Permalink
Merge pull request #25 from grummbeer/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
amenk authored Dec 9, 2023
2 parents 2b249b3 + 4e7cf77 commit 1fdb337
Show file tree
Hide file tree
Showing 73 changed files with 1,350 additions and 821 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [ push ]
on: [ push, pull_request ]

jobs:
check:
Expand All @@ -19,8 +19,15 @@ jobs:
- name: Check formatting
run: ./vendor/bin/ecs check

- name: Analyse code
run: ./vendor/bin/phpstan

- name: Run tests
uses: php-actions/phpunit@v3
env:
XDEBUG_MODE: coverage
with:
version: 8.5
version: 10.5
php_version: 8.1
php_extensions: "xdebug"
coverage_text: true
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ Run the fixer before push.
```shell
./vendor/bin/ecs --fix
```

Run phpstan before push

```shell
./vendor/bin/phpstan analyse
```
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
"require": {
"php": "^8.1",
"ext-dom": "*",
"ext-simplexml": "*",
"moneyphp/money": "^4.3"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"phpunit/phpunit": "^10.5",
"mockery/mockery": "*",
"mikey179/vfsstream": "^1.6",
"symplify/easy-coding-standard": "^12.0"
"symplify/easy-coding-standard": "^12.0",
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 4 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
Expand All @@ -23,6 +25,8 @@
YodaStyleFixer::class,
OrderedClassElementsFixer::class,
NativeFunctionInvocationFixer::class,
PhpdocTypesOrderFixer::class,
PhpdocOrderFixer::class,
]);

$ecsConfig->sets([
Expand Down
16 changes: 16 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters:
ignoreErrors:
-
message: "#^Method AqBanking\\\\AccountMatcher\\:\\:__construct\\(\\) has parameter \\$existingAccounts with no value type specified in iterable type array\\.$#"
count: 1
path: src/AccountMatcher.php

-
message: "#^Method AqBanking\\\\Arrayable\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Arrayable.php

-
message: "#^Method AqBanking\\\\Command\\\\ListAccountsCommand\\:\\:execute\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Command/ListAccountsCommand.php
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- phpstan-baseline.neon
parameters:
level: 6
paths:
- src
33 changes: 12 additions & 21 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="true" beStrictAboutCoverageMetadata="true">
<coverage/>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
54 changes: 15 additions & 39 deletions src/Account.php
Original file line number Diff line number Diff line change
@@ -1,66 +1,42 @@
<?php

declare(strict_types=1);

namespace AqBanking;

class Account implements AccountInterface, Arrayable
{
/**
* @var BankCode
*/
private $bankCode;

/**
* @var string
*/
private $accountNumber;

/**
* @var string
*/
private $accountHolderName;

/**
* @param string $accountNumber
* @param string $accountHolderName
* @return \AqBanking\Account
*/
public function __construct(BankCode $bankCode, $accountNumber, $accountHolderName = '')
{
$this->bankCode = $bankCode;
$this->accountNumber = $accountNumber;
$this->accountHolderName = $accountHolderName;
public function __construct(
private readonly BankCode $bankCode,
private readonly string $accountNumber,
private readonly string $accountHolderName = '',
) {
}

/**
* @return BankCode
*/
public function getBankCode()
public function getBankCode(): BankCode
{
return $this->bankCode;
}

/**
* @return string
*/
public function getAccountNumber()
public function getAccountNumber(): string
{
return $this->accountNumber;
}

/**
* @return string
*/
public function getAccountHolderName()
public function getAccountHolderName(): string
{
return $this->accountHolderName;
}

public function toArray()
/**
* @return array<string, string>
*/
public function toArray(): array
{
return [
'bankCode' => $this->getBankCode()->getString(),
'accountHolderName' => $this->getAccountHolderName(),
'accountNumber' => $this->getAccountNumber(),
'accountHolderName' => $this->getAccountHolderName(),
];
}
}
17 changes: 5 additions & 12 deletions src/AccountInterface.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
<?php

declare(strict_types=1);

namespace AqBanking;

interface AccountInterface
{
/**
* @return BankCode
*/
public function getBankCode();
public function getBankCode(): BankCode;

/**
* @return string
*/
public function getAccountHolderName();
public function getAccountHolderName(): string;

/**
* @return string
*/
public function getAccountNumber();
public function getAccountNumber(): string;
}
20 changes: 8 additions & 12 deletions src/AccountMatcher.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
<?php

declare(strict_types=1);

namespace AqBanking;

use AqBanking\Command\ListAccountsCommand;

/**
* Find account in existing account database
* @package AqBanking
*/
class AccountMatcher
{
/**
* @var \DOMDocument
*/
private $array;

public function __construct($array)
{
$this->array = $array;
public function __construct(
private readonly array $existingAccounts
) {
}

public function getExistingAccount(Account $account)
public function getExistingAccount(Account $account): ?ExistingAccount
{
foreach ($this->array as $record) {
foreach ($this->existingAccounts as $record) {
if (
$account->getBankCode()->getString() === $record[ListAccountsCommand::BANK] &&
$account->getAccountNumber() === $record[ListAccountsCommand::NUMBER]
) {
return new ExistingAccount($account, $record[ListAccountsCommand::UNIQUE_ID]);
return new ExistingAccount($account, (int) $record[ListAccountsCommand::UNIQUE_ID]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Arrayable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface Arrayable
{
public function toArray();
public function toArray(): array;
}
45 changes: 11 additions & 34 deletions src/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,37 @@

namespace AqBanking;

use DateTime;
use Money\Money;

class Balance implements Arrayable
{
/**
* @var string
*/
private $type;

/**
* @var \DateTime
*/
private $date;

/**
* @var Money
*/
private $value;

public function __construct(
\DateTime $date,
Money $value,
string $type
private readonly DateTime $date,
private readonly Money $value,
private readonly string $type
) {
$this->date = $date;
$this->value = $value;
$this->type = $type;
}

/**
* @return \DateTime
*/
public function getDate()
public function getDate(): DateTime
{
return $this->date;
}

/**
* @return string
*/
public function getType()
public function getType(): string
{
return $this->type;
}

/**
* @return \Money\Money
*/
public function getValue()
public function getValue(): Money
{
return $this->value;
}

public function toArray()
/**
* @return array<string, array<int|string>|string>
*/
public function toArray(): array
{
return [
'type' => $this->getType(),
Expand Down
Loading

0 comments on commit 1fdb337

Please sign in to comment.