Skip to content

Commit e8bbf0e

Browse files
authored
Add PHP CS Fixer (#375)
1 parent a7896f8 commit e8bbf0e

30 files changed

+214
-277
lines changed

.github/workflows/rector.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1+
name: Rector + PHP CS Fixer
2+
13
on:
24
pull_request_target:
35
paths:
46
- 'src/**'
57
- 'tests/**'
6-
- '.github/workflows/rector.yml'
8+
- '.github/workflows/rector-cs.yml'
79
- 'composer.json'
810
- 'rector.php'
11+
- '.php-cs-fixer.dist.php'
912

10-
name: Rector
13+
permissions:
14+
contents: read
1115

1216
concurrency:
1317
group: ${{ github.workflow }}-${{ github.ref }}
1418
cancel-in-progress: true
1519

1620
jobs:
1721
rector:
18-
uses: yiisoft/actions/.github/workflows/rector.yml@master
22+
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
1923
secrets:
2024
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
2125
with:
2226
repository: ${{ github.event.pull_request.head.repo.full_name }}
23-
php: >-
24-
['8.4']
27+
php: '8.4'
2528
required-packages: >-
2629
['db']

.gitignore

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ composer.phar
2323
# Mac DS_Store Files
2424
.DS_Store
2525

26-
# phpunit itself is not needed
27-
phpunit.phar
28-
29-
# local phpunit config and cache
26+
# PHPUnit
27+
/phpunit.phar
3028
/phpunit.xml
3129
/.phpunit.result.cache
3230

33-
# local tests configuration
34-
/tests/data/config.local.php
31+
# PHP CS Fixer
32+
/.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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-CS3.0' => true,
18+
'no_unused_imports' => true,
19+
'ordered_class_elements' => true,
20+
'class_attributes_separation' => ['elements' => ['method' => 'one']],
21+
])
22+
->setFinder($finder);

.styleci.yml

Lines changed: 0 additions & 85 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"yiisoft/db": "dev-master"
3636
},
3737
"require-dev": {
38+
"friendsofphp/php-cs-fixer": "^3.89.1",
3839
"maglnet/composer-require-checker": "^4.7.1",
3940
"phpunit/phpunit": "^10.5.45",
4041
"rector/rector": "^2.0.10",

src/Builder/InBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function build(ExpressionInterface $expression, array &$params = []): str
5656
*
5757
* @return string|null `null` when split isn't required. Otherwise - built SQL condition.
5858
*/
59-
protected function splitCondition(In|NotIn $condition, array &$params): string|null
59+
protected function splitCondition(In|NotIn $condition, array &$params): ?string
6060
{
6161
$operator = match ($condition::class) {
6262
In::class => 'IN',
@@ -80,7 +80,7 @@ protected function splitCondition(In|NotIn $condition, array &$params): string|n
8080

8181
for ($i = 0; $i < $count; $i += $maxParameters) {
8282
$slices[] = $this->queryBuilder->createConditionFromArray(
83-
[$operator, $column, array_slice($values, $i, $maxParameters)]
83+
[$operator, $column, array_slice($values, $i, $maxParameters)],
8484
);
8585
}
8686

src/Column/BooleanColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function dbTypecast(mixed $value): string|ExpressionInterface|null
2222
};
2323
}
2424

25-
public function phpTypecast(mixed $value): bool|null
25+
public function phpTypecast(mixed $value): ?bool
2626
{
2727
if ($value === null) {
2828
return null;

src/Column/ColumnBuilder.php

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

99
final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder
1010
{
11-
public static function binary(int|null $size = null): BinaryColumn
11+
public static function binary(?int $size = null): BinaryColumn
1212
{
1313
return new BinaryColumn(ColumnType::BINARY, size: $size);
1414
}
@@ -18,27 +18,27 @@ public static function boolean(): BooleanColumn
1818
return new BooleanColumn(ColumnType::BOOLEAN);
1919
}
2020

21-
public static function timestamp(int|null $size = 0): DateTimeColumn
21+
public static function timestamp(?int $size = 0): DateTimeColumn
2222
{
2323
return new DateTimeColumn(ColumnType::TIMESTAMP, size: $size);
2424
}
2525

26-
public static function datetime(int|null $size = 0): DateTimeColumn
26+
public static function datetime(?int $size = 0): DateTimeColumn
2727
{
2828
return new DateTimeColumn(ColumnType::DATETIME, size: $size);
2929
}
3030

31-
public static function datetimeWithTimezone(int|null $size = 0): DateTimeColumn
31+
public static function datetimeWithTimezone(?int $size = 0): DateTimeColumn
3232
{
3333
return new DateTimeColumn(ColumnType::DATETIMETZ, size: $size);
3434
}
3535

36-
public static function time(int|null $size = 0): DateTimeColumn
36+
public static function time(?int $size = 0): DateTimeColumn
3737
{
3838
return new DateTimeColumn(ColumnType::TIME, size: $size);
3939
}
4040

41-
public static function timeWithTimezone(int|null $size = 0): DateTimeColumn
41+
public static function timeWithTimezone(?int $size = 0): DateTimeColumn
4242
{
4343
return new DateTimeColumn(ColumnType::TIMETZ, size: $size);
4444
}

src/Column/ColumnDefinitionBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ protected function buildCheck(ColumnInterface $column): string
6262
}
6363

6464
return match ($column->getType()) {
65-
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON =>
66-
version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '<')
65+
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON
66+
=> version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '<')
6767
? ' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IS JSON)'
6868
: '',
69-
ColumnType::BOOLEAN =>
70-
' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IN (0,1))',
69+
ColumnType::BOOLEAN
70+
=> ' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IN (0,1))',
7171
default => '',
7272
};
7373
}
@@ -124,8 +124,8 @@ protected function getDbType(ColumnInterface $column): string
124124
ColumnType::TIME => 'interval day(0) to second',
125125
ColumnType::TIMETZ => 'interval day(0) to second',
126126
ColumnType::DATE => 'date',
127-
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON =>
128-
version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '>=')
127+
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON
128+
=> version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '>=')
129129
? 'json'
130130
: 'clob',
131131
default => 'varchar2',

src/Column/ColumnFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
final class ColumnFactory extends AbstractColumnFactory
1818
{
19-
private const DATETIME_REGEX = "/^(?:TIMESTAMP|DATE|INTERVAL|to_timestamp(?:_tz)?\(|to_date\(|to_dsinterval\()\s*'(?:\d )?([^']+)/";
20-
2119
/**
2220
* The mapping from physical column types (keys) to abstract column types (values).
2321
*
@@ -54,6 +52,7 @@ final class ColumnFactory extends AbstractColumnFactory
5452
/** Deprecated */
5553
'long' => ColumnType::TEXT,
5654
];
55+
private const DATETIME_REGEX = "/^(?:TIMESTAMP|DATE|INTERVAL|to_timestamp(?:_tz)?\(|to_date\(|to_dsinterval\()\s*'(?:\d )?([^']+)/";
5756

5857
protected function columnDefinitionParser(): ColumnDefinitionParser
5958
{

0 commit comments

Comments
 (0)