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
13 changes: 8 additions & 5 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
name: Rector + PHP CS Fixer

on:
pull_request_target:
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/rector.yml'
- '.github/workflows/rector-cs.yml'
- 'composer.json'
- 'rector.php'
- '.php-cs-fixer.dist.php'

name: Rector
permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
php: >-
['8.4']
php: '8.4'
required-packages: >-
['db']
10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ composer.phar
# Mac DS_Store Files
.DS_Store

# phpunit itself is not needed
phpunit.phar

# local phpunit config and cache
# PHPUnit
/phpunit.phar
/phpunit.xml
/.phpunit.result.cache

# local tests configuration
/tests/data/config.local.php
# PHP CS Fixer
/.php-cs-fixer.cache
22 changes: 22 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = (new Finder())->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return (new Config())
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS3.0' => true,
'no_unused_imports' => true,
'ordered_class_elements' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"yiisoft/db": "dev-master"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.89.1",
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.45",
"rector/rector": "^2.0.10",
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/InBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function build(ExpressionInterface $expression, array &$params = []): str
*
* @return string|null `null` when split isn't required. Otherwise - built SQL condition.
*/
protected function splitCondition(In|NotIn $condition, array &$params): string|null
protected function splitCondition(In|NotIn $condition, array &$params): ?string
{
$operator = match ($condition::class) {
In::class => 'IN',
Expand All @@ -80,7 +80,7 @@ protected function splitCondition(In|NotIn $condition, array &$params): string|n

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

Expand Down
2 changes: 1 addition & 1 deletion src/Column/BooleanColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function dbTypecast(mixed $value): string|ExpressionInterface|null
};
}

public function phpTypecast(mixed $value): bool|null
public function phpTypecast(mixed $value): ?bool
{
if ($value === null) {
return null;
Expand Down
12 changes: 6 additions & 6 deletions src/Column/ColumnBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder
{
public static function binary(int|null $size = null): BinaryColumn
public static function binary(?int $size = null): BinaryColumn
{
return new BinaryColumn(ColumnType::BINARY, size: $size);
}
Expand All @@ -18,27 +18,27 @@ public static function boolean(): BooleanColumn
return new BooleanColumn(ColumnType::BOOLEAN);
}

public static function timestamp(int|null $size = 0): DateTimeColumn
public static function timestamp(?int $size = 0): DateTimeColumn
{
return new DateTimeColumn(ColumnType::TIMESTAMP, size: $size);
}

public static function datetime(int|null $size = 0): DateTimeColumn
public static function datetime(?int $size = 0): DateTimeColumn
{
return new DateTimeColumn(ColumnType::DATETIME, size: $size);
}

public static function datetimeWithTimezone(int|null $size = 0): DateTimeColumn
public static function datetimeWithTimezone(?int $size = 0): DateTimeColumn
{
return new DateTimeColumn(ColumnType::DATETIMETZ, size: $size);
}

public static function time(int|null $size = 0): DateTimeColumn
public static function time(?int $size = 0): DateTimeColumn
{
return new DateTimeColumn(ColumnType::TIME, size: $size);
}

public static function timeWithTimezone(int|null $size = 0): DateTimeColumn
public static function timeWithTimezone(?int $size = 0): DateTimeColumn
{
return new DateTimeColumn(ColumnType::TIMETZ, size: $size);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Column/ColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ protected function buildCheck(ColumnInterface $column): string
}

return match ($column->getType()) {
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON =>
version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '<')
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON
=> version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '<')
? ' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IS JSON)'
: '',
ColumnType::BOOLEAN =>
' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IN (0,1))',
ColumnType::BOOLEAN
=> ' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IN (0,1))',
default => '',
};
}
Expand Down Expand Up @@ -124,8 +124,8 @@ protected function getDbType(ColumnInterface $column): string
ColumnType::TIME => 'interval day(0) to second',
ColumnType::TIMETZ => 'interval day(0) to second',
ColumnType::DATE => 'date',
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON =>
version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '>=')
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON
=> version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '>=')
? 'json'
: 'clob',
default => 'varchar2',
Expand Down
3 changes: 1 addition & 2 deletions src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

final class ColumnFactory extends AbstractColumnFactory
{
private const DATETIME_REGEX = "/^(?:TIMESTAMP|DATE|INTERVAL|to_timestamp(?:_tz)?\(|to_date\(|to_dsinterval\()\s*'(?:\d )?([^']+)/";

/**
* The mapping from physical column types (keys) to abstract column types (values).
*
Expand Down Expand Up @@ -54,6 +52,7 @@ final class ColumnFactory extends AbstractColumnFactory
/** Deprecated */
'long' => ColumnType::TEXT,
];
private const DATETIME_REGEX = "/^(?:TIMESTAMP|DATE|INTERVAL|to_timestamp(?:_tz)?\(|to_date\(|to_dsinterval\()\s*'(?:\d )?([^']+)/";

protected function columnDefinitionParser(): ColumnDefinitionParser
{
Expand Down
4 changes: 2 additions & 2 deletions src/Column/DateTimeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public function dbTypecast(mixed $value): float|int|string|ExpressionInterface|n
return match ($this->getType()) {
ColumnType::TIMESTAMP, ColumnType::DATETIME, ColumnType::DATETIMETZ => new Expression("TIMESTAMP '$value'"),
ColumnType::TIME, ColumnType::TIMETZ => new Expression(
"INTERVAL '$value' DAY(0) TO SECOND" . (($size = $this->getSize()) !== null ? "($size)" : '')
"INTERVAL '$value' DAY(0) TO SECOND" . (($size = $this->getSize()) !== null ? "($size)" : ''),
),
ColumnType::DATE => new Expression("DATE '$value'"),
default => $value,
};
}

public function phpTypecast(mixed $value): DateTimeImmutable|null
public function phpTypecast(mixed $value): ?DateTimeImmutable
{
if (is_string($value) && match ($this->getType()) {
ColumnType::TIME, ColumnType::TIMETZ => true,
Expand Down
4 changes: 2 additions & 2 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function insertReturningPks(string $table, array|QueryInterface $columns)

if ($columns instanceof QueryInterface) {
throw new NotSupportedException(
__METHOD__ . '() is not supported by Oracle when inserting sub-query.'
__METHOD__ . '() is not supported by Oracle when inserting sub-query.',
);
}

Expand Down Expand Up @@ -130,7 +130,7 @@ protected function bindPendingParams(): void
$name,
$paramsPassedByReference[$name],
$param->type,
strlen((string) $param->value)
strlen((string) $param->value),
);
} else {
$this->pdoStatement?->bindValue($name, $param->value, $param->type);
Expand Down
6 changes: 3 additions & 3 deletions src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function addForeignKey(
string $referenceTable,
array|string $referenceColumns,
?string $delete = null,
?string $update = null
?string $update = null,
): string {
$sql = 'ALTER TABLE ' . $this->quoter->quoteTableName($table)
. ' ADD CONSTRAINT ' . $this->quoter->quoteColumnName($name)
Expand Down Expand Up @@ -98,7 +98,7 @@ public function dropTable(string $table, bool $ifExists = false, bool $cascade =

public function renameTable(string $oldName, string $newName): string
{
return 'ALTER TABLE ' . $this->quoter->quoteTableName($oldName) . ' RENAME TO ' .
$this->quoter->quoteTableName($newName);
return 'ALTER TABLE ' . $this->quoter->quoteTableName($oldName) . ' RENAME TO '
. $this->quoter->quoteTableName($newName);
}
}
Loading