Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.phpunit.result.cache
composer.lock
.phpunit.cache
/node_modules
/var
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint-staged
12 changes: 5 additions & 7 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
EOF;

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->append([
__FILE__,
__DIR__ . '/rector.php',
->in(__DIR__)
->notPath([
'node_modules',
'var',
])
;

Expand All @@ -53,4 +50,5 @@
'declare_strict_types' => true,
])
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/var/tools/.php-cs-fixer.cache')
->setFinder($finder);
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
"require": {
"php": ">=8.2"
},
"config": {
"bump-after-update": "dev"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.93",
"phpunit/phpunit": "^10.5.26",
"phpstan/phpstan": "^2",
"rector/rector": "^2",
"vimeo/psalm": "^5.26"
"dg/bypass-finals": "^1.9",
"friendsofphp/php-cs-fixer": "^3.93.1",
"phpstan/phpstan": "^2.1.37",
"phpunit/phpunit": "^10.5.26|^11.5.50|^12.0",
"rector/rector": "^2.3.5",
"rector/swiss-knife": "^2.3.5",
"vimeo/psalm": "^5.26|^6.14.3"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"devDependencies": {
"husky": ">=9.1.6",
"lint-staged": ">=15.2.10"
},
"lint-staged": {
"*.php": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php"
},
"scripts": {
"prepare": "husky"
}
}
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
parameters:
level: max
tmpDir: var/tools/phpstan
paths:
- src
- tests
ignoreErrors:
- identifier: method.unresolvableReturnType
path: tests/*
- identifier: method.nonObject
path: tests/*
- identifier: argument.unresolvableType
path: tests/*
5 changes: 4 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" executionOrder="random" resolveDependencies="true" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" executionOrder="random" resolveDependencies="true" colors="true" cacheDirectory="var/tools/.phpunit.cache" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd">
<coverage/>
<testsuites>
<testsuite name="Test Suite">
Expand All @@ -15,4 +15,7 @@
<directory>./src</directory>
</include>
</source>
<extensions>
<bootstrap class="DG\BypassFinals\PHPUnitExtension"/>
</extensions>
</phpunit>
17 changes: 13 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@
* with this source code in the file LICENSE.
*/

use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
->withCache(__DIR__ . '/var/tools/rector')
->withImportNames()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
->withPhpSets()
->withSets([
PHPUnitSetList::PHPUNIT_100,
]);
->withComposerBased(
phpunit: true,
)
->withPreparedSets(
deadCode: true,
codeQuality: true
)
->withSkip([
FlipTypeControlToUseExclusiveTypeRector::class,
])
;
2 changes: 1 addition & 1 deletion src/Banking/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use DateTimeImmutable;

class Balance extends Element
final class Balance extends Element
{
public function __construct(
private readonly string $bankCode,
Expand Down
2 changes: 1 addition & 1 deletion src/Banking/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use DateTimeInterface;

class Header extends Element
final class Header extends Element
{
public function __construct(
private readonly int $sequenceNumber,
Expand Down
2 changes: 1 addition & 1 deletion src/Banking/Noop.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

namespace Silarhi\Cfonb\Banking;

class Noop extends Element
final class Noop extends Element
{
}
5 changes: 2 additions & 3 deletions src/Banking/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

use DateTimeImmutable;

class Operation extends Element
final class Operation extends Element
{
/** @var OperationDetail[] */
private array $details;
private array $details = [];

public function __construct(
private readonly string $bankCode,
Expand All @@ -37,7 +37,6 @@ public function __construct(
private readonly ?string $exemptCode,
private readonly ?string $bankOperationReference,
) {
$this->details = [];
}

public function getBankCode(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Banking/OperationDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use DateTimeImmutable;

class OperationDetail extends Element
final class OperationDetail extends Element
{
public function __construct(
private readonly string $bankCode,
Expand Down
15 changes: 4 additions & 11 deletions src/Banking/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@

use Silarhi\Cfonb\Exceptions\BalanceUnavailableException;

class Statement extends Element
final class Statement extends Element
{
private ?Balance $oldBalance;
private ?Balance $oldBalance = null;

private ?Balance $newBalance;
private ?Balance $newBalance = null;

/** @var Operation[] */
private array $operations;

public function __construct()
{
$this->oldBalance = null;
$this->newBalance = null;
$this->operations = [];
}
private array $operations = [];

public function addOperation(Operation $operation): self
{
Expand Down
5 changes: 2 additions & 3 deletions src/Banking/Total.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use DateTimeInterface;

class Total extends Element
final class Total extends Element
{
public function __construct(
private readonly int $sequenceNumber,
Expand All @@ -31,10 +31,9 @@ public function __construct(
private readonly string $recipientCounterCode2,
private readonly string $recipientAccountNumber2,
private readonly ?string $recipientName2,
private ?string $processingCenterCode,
private readonly ?string $processingCenterCode,
private readonly float $totalAmount,
) {
$this->processingCenterCode = $processingCenterCode;
}

public function getSequenceNumber(): int
Expand Down
2 changes: 1 addition & 1 deletion src/Banking/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use DateTimeInterface;

class Transaction extends Element
final class Transaction extends Element
{
public function __construct(
private readonly int $sequenceNumber,
Expand Down
15 changes: 4 additions & 11 deletions src/Banking/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@
use Silarhi\Cfonb\Exceptions\HeaderUnavailableException;
use Silarhi\Cfonb\Exceptions\TotalUnavailableException;

class Transfer extends Element
final class Transfer extends Element
{
private ?Header $header;
private ?Header $header = null;

/**
* @var Transaction[]
*/
private array $transactions;
private array $transactions = [];

private ?Total $total;

public function __construct()
{
$this->header = null;
$this->total = null;
$this->transactions = [];
}
private ?Total $total = null;

public function setHeader(Header $header): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Cfonb120Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

use function sprintf;

class Cfonb120Reader
final readonly class Cfonb120Reader
{
final public const LINE_LENGTH = 120;

private readonly FileParser $fileParser;
private FileParser $fileParser;

public function __construct(?FileParser $fileParser = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Cfonb240Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

use function sprintf;

class Cfonb240Reader
final readonly class Cfonb240Reader
{
final public const LINE_LENGTH = 240;

private readonly FileParser $fileParser;
private FileParser $fileParser;

public function __construct(?FileParser $fileParser = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/CfonbCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Silarhi\Cfonb;

class CfonbCodes
final class CfonbCodes
{
/** @var string[][] */
public static array $codes = [
Expand Down
6 changes: 3 additions & 3 deletions src/CfonbReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
use Silarhi\Cfonb\Banking\Statement;
use Silarhi\Cfonb\Banking\Transfer;

class CfonbReader
final readonly class CfonbReader
{
public function __construct(
private readonly Cfonb120Reader $cfonb120Reader = new Cfonb120Reader(),
private readonly Cfonb240Reader $cfonb240Reader = new Cfonb240Reader(),
private Cfonb120Reader $cfonb120Reader = new Cfonb120Reader(),
private Cfonb240Reader $cfonb240Reader = new Cfonb240Reader(),
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface ParserInterface
public function parse(string $content, bool $strict): Element;

/**
* Checks if current line is handled by the parser
* Checks if the parser handles the current line
*
* @return bool true if the line is handled by the current parser, false otherwise
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Parser/Cfonb120/AbstractCfonb120Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Silarhi\Cfonb\Parser\Cfonb120;

use Override;
use Silarhi\Cfonb\Cfonb120Reader;
use Silarhi\Cfonb\Contracts\ParserInterface;

Expand All @@ -27,6 +28,7 @@ abstract protected function getSupportedCode(): string;
/**
* {@inheritdoc}
*/
#[Override]
public function supports(string $content): bool
{
return Cfonb120Reader::LINE_LENGTH === strlen($content) && $this->getSupportedCode() === substr($content, 0, 2);
Expand Down
3 changes: 3 additions & 0 deletions src/Parser/Cfonb120/Line01Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Silarhi\Cfonb\Parser\Cfonb120;

use Override;
use Silarhi\Cfonb\Banking\Balance;
use Silarhi\Cfonb\Parser\AmountParser;
use Silarhi\Cfonb\Parser\DateParser;
Expand Down Expand Up @@ -48,6 +49,7 @@ public function __construct()
]);
}

#[Override]
public function parse(string $content, bool $strict): Balance
{
$regexMatch = $this->lineParser->parse($content);
Expand All @@ -62,6 +64,7 @@ public function parse(string $content, bool $strict): Balance
);
}

#[Override]
protected function getSupportedCode(): string
{
return '01';
Expand Down
3 changes: 3 additions & 0 deletions src/Parser/Cfonb120/Line04Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Silarhi\Cfonb\Parser\Cfonb120;

use Override;
use Silarhi\Cfonb\Banking\Operation;
use Silarhi\Cfonb\Parser\AmountParser;
use Silarhi\Cfonb\Parser\DateParser;
Expand Down Expand Up @@ -54,6 +55,7 @@ public function __construct()
]);
}

#[Override]
public function parse(string $content, bool $strict): Operation
{
$regexMatch = $this->lineParser->parse($content);
Expand All @@ -76,6 +78,7 @@ public function parse(string $content, bool $strict): Operation
);
}

#[Override]
protected function getSupportedCode(): string
{
return '04';
Expand Down
Loading