Skip to content

Commit 6ad1fb7

Browse files
committed
cs
1 parent c723293 commit 6ad1fb7

34 files changed

+149
-88
lines changed

.github/workflows/cs.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: cs fixer
2+
3+
on: [ pull_request_target ]
4+
5+
jobs:
6+
php-cs-fixer:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: write
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
with:
14+
ref: ${{ github.head_ref }}
15+
repository: ${{ github.event.pull_request.head.repo.full_name }}
16+
17+
- name: Install PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: 8.2
21+
tools: composer:v2
22+
coverage: none
23+
24+
- name: Install Composer dependencies
25+
uses: "ramsey/composer-install@v3"
26+
27+
- name: Run PHP CS Fixer
28+
run: composer php-cs-fixer
29+
30+
- name: Run Rector
31+
run: composer rector
32+
33+
- name: Commit changes
34+
uses: stefanzweifel/git-auto-commit-action@v5
35+
with:
36+
commit_message: "Apply PHP CS Fixer and Rector changes (CI)"
37+
file_pattern: '*.php'
38+
disable_globbing: true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
# PHPUnit
55
.phpunit.cache
6+
7+
# PHP CS Fixer
8+
/.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
8+
9+
$finder = (new Finder())->in([
10+
__DIR__ . '/src',
11+
__DIR__ . '/tests',
12+
]);
13+
14+
return (new Config())
15+
->setParallelConfig(ParallelConfigFactory::detect())
16+
->setRules([
17+
'@PER-CS2.0' => true,
18+
'no_unused_imports' => true,
19+
])
20+
->setFinder($finder);

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
"brick/money": "^0.10.0"
2121
},
2222
"require-dev": {
23+
"friendsofphp/php-cs-fixer": "^3.69",
24+
"infection/infection": "^0.29.12",
2325
"maglnet/composer-require-checker": "^4.16.1",
2426
"phpunit/phpunit": "^12.0.3",
25-
"infection/infection": "^0.29.12",
27+
"rector/rector": "^2.0",
2628
"vimeo/psalm": "^6.8"
2729
},
2830
"config": {
@@ -33,6 +35,8 @@
3335
}
3436
},
3537
"scripts": {
36-
"infection": "infection --ignore-msi-with-no-mutations --only-covered"
38+
"php-cs-fixer": "php-cs-fixer fix",
39+
"infection": "infection --ignore-msi-with-no-mutations --only-covered",
40+
"rector": "rector"
3741
}
3842
}

rector.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
7+
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
8+
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
9+
use Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector;
10+
11+
return RectorConfig::configure()
12+
->withPaths([
13+
__DIR__ . '/src',
14+
__DIR__ . '/tests',
15+
])
16+
->withPhpSets(php83: true)
17+
->withSkip([
18+
ClosureToArrowFunctionRector::class,
19+
NullToStrictStringFuncCallArgRector::class,
20+
ClassPropertyAssignToConstructorPromotionRector::class,
21+
]);

src/Domain/Account/Account.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
final class Account
1010
{
11-
private const NAME_CHARS_LIMIT = 50;
11+
private const int NAME_CHARS_LIMIT = 50;
1212

1313
/**
1414
* @psalm-var non-empty-string|null
@@ -62,8 +62,8 @@ private function setName(?string $name): void
6262
throw new InvalidArgumentException(
6363
sprintf(
6464
'Account name must be null or non-empty string no greater than %d symbols.',
65-
self::NAME_CHARS_LIMIT
66-
)
65+
self::NAME_CHARS_LIMIT,
66+
),
6767
);
6868
}
6969
/** @psalm-var non-empty-string $name */

src/Domain/Account/AccountChartId.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
final readonly class AccountChartId
88
{
99
public function __construct(
10-
public string $value
11-
) {
12-
}
10+
public string $value,
11+
) {}
1312

1413
public function isEqualTo(AccountChartId $id): bool
1514
{

src/Domain/Account/AccountId.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
final readonly class AccountId
88
{
99
public function __construct(
10-
public string $value
11-
) {
12-
}
10+
public string $value,
11+
) {}
1312

1413
public function isEqualTo(AccountId $id): bool
1514
{

src/Domain/Account/AccountManager.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
use PhpFinance\DoubleEntry\Domain\Account\Exception\AccountDeletionNotPossibleException;
88
use PhpFinance\DoubleEntry\Domain\Posting\PostingRepositoryInterface;
99

10-
final class AccountManager
10+
final readonly class AccountManager
1111
{
1212
public function __construct(
13-
private readonly AccountRepositoryInterface $accountRepository,
14-
private readonly AccountIdFactoryInterface $accountIdFactory,
15-
private readonly PostingRepositoryInterface $postingRepository,
16-
) {
17-
}
13+
private AccountRepositoryInterface $accountRepository,
14+
private AccountIdFactoryInterface $accountIdFactory,
15+
private PostingRepositoryInterface $postingRepository,
16+
) {}
1817

1918
public function get(AccountId $id): Account
2019
{

src/Domain/Account/Exception/AccountDeletionNotPossibleException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use RuntimeException;
88

9-
final class AccountDeletionNotPossibleException extends RuntimeException
10-
{
11-
}
9+
final class AccountDeletionNotPossibleException extends RuntimeException {}

src/Domain/Account/Exception/AccountNotFoundException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use RuntimeException;
88

9-
final class AccountNotFoundException extends RuntimeException
10-
{
11-
}
9+
final class AccountNotFoundException extends RuntimeException {}

src/Domain/Calculator/Filter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public function __construct(
1818
private ?DateTimeImmutable $dateFrom = null,
1919
private ?DateTimeImmutable $dateTo = null,
2020
private array $currencies = [],
21-
) {
22-
}
21+
) {}
2322

2423
public function getDimensions(): array
2524
{

src/Domain/Posting/Entry.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public function __construct(
2222
public Money $amount,
2323
public AccountId $accountId,
2424
private array $dimensions = [],
25-
) {
26-
}
25+
) {}
2726

2827
/**
2928
* @throws DimensionNotFoundException

src/Domain/Posting/Exception/DimensionNotFoundException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public function __construct(int|string $name)
1313
parent::__construct(
1414
sprintf(
1515
'Entry does not have dimension "%s".',
16-
$name
17-
)
16+
$name,
17+
),
1818
);
1919
}
2020
}

src/Domain/Posting/Exception/PostingNotFoundException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use RuntimeException;
88

9-
final class PostingNotFoundException extends RuntimeException
10-
{
11-
}
9+
final class PostingNotFoundException extends RuntimeException {}

src/Domain/Posting/Factory/EntryData.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
public function __construct(
1212
public Account $account,
1313
public array $dimensions = [],
14-
) {
15-
}
14+
) {}
1615
}

src/Domain/Posting/Factory/PostingFactory.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
use PhpFinance\DoubleEntry\Domain\Posting\Entry;
1111
use PhpFinance\DoubleEntry\Domain\Posting\Posting;
1212

13-
final class PostingFactory
13+
final readonly class PostingFactory
1414
{
1515
public function __construct(
1616
private PostingIdFactoryInterface $postingIdFactory,
17-
) {
18-
}
17+
) {}
1918

2019
public function create(
2120
DateTimeImmutable $date,
@@ -40,7 +39,7 @@ public function create(
4039
$amount,
4140
$creditData->account->id,
4241
$creditData->dimensions,
43-
)
42+
),
4443
);
4544
}
4645
}

src/Domain/Posting/Posting.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
public function __construct(
1717
public PostingId $id,
1818
public Entry $debit,
19-
public Entry $credit
20-
) {
21-
}
19+
public Entry $credit,
20+
) {}
2221

2322
public function getDate(): DateTimeImmutable
2423
{

src/Domain/Posting/PostingId.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
final readonly class PostingId
88
{
99
public function __construct(
10-
public string $value
11-
) {
12-
}
10+
public string $value,
11+
) {}
1312

1413
public function isEqualTo(PostingId $id): bool
1514
{

src/Domain/Transaction/Exception/TransactionNotFoundException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use RuntimeException;
88

9-
final class TransactionNotFoundException extends RuntimeException
10-
{
11-
}
9+
final class TransactionNotFoundException extends RuntimeException {}

src/Domain/Transaction/Factory/PostingData.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ public function __construct(
1313
public Money $amount,
1414
public EntryData $debitData,
1515
public EntryData $creditData,
16-
) {
17-
}
16+
) {}
1817
}

src/Domain/Transaction/Factory/TransactionFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
use PhpFinance\DoubleEntry\Domain\Posting\Factory\PostingFactory;
99
use PhpFinance\DoubleEntry\Domain\Transaction\Transaction;
1010

11-
final class TransactionFactory
11+
final readonly class TransactionFactory
1212
{
1313
public function __construct(
1414
private TransactionIdFactoryInterface $transactionIdFactory,
1515
private PostingFactory $postingFactory,
16-
) {
17-
}
16+
) {}
1817

1918
public function create(
2019
DateTimeImmutable $date,

src/Domain/Transaction/Transaction.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
public function __construct(
2020
public TransactionId $id,
2121
public array $postings,
22-
) {
23-
}
22+
) {}
2423

2524
public function getDate(): DateTimeImmutable
2625
{

src/Domain/Transaction/TransactionId.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
final readonly class TransactionId
88
{
99
public function __construct(
10-
public string $value
11-
) {
12-
}
10+
public string $value,
11+
) {}
1312

1413
public function isEqualTo(TransactionId $id): bool
1514
{

tests/Account/AbstractAccountManagerTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function testDeleteWithChildren(): void
144144
$accountIncomes = TestFactory::createAccount('incomes');
145145
$accountSalary = TestFactory::createAccount(
146146
'salary',
147-
parent: $accountIncomes
147+
parent: $accountIncomes,
148148
);
149149
$accountRepository = $this->createAccountRepository($accountIncomes, $accountSalary);
150150
$accountManager = $this->createAccountManager(
@@ -161,7 +161,7 @@ public function testDeleteWithChildrenAndNamedAccounts(): void
161161
$accountIncomes = TestFactory::createAccount('acc1', name: 'Incomes');
162162
$accountSalary = TestFactory::createAccount(
163163
'salary',
164-
parent: $accountIncomes
164+
parent: $accountIncomes,
165165
);
166166
$accountRepository = $this->createAccountRepository($accountIncomes, $accountSalary);
167167
$accountManager = $this->createAccountManager(

0 commit comments

Comments
 (0)