diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml index 4f751c0..d57ddf2 100644 --- a/.github/workflows/code-checks.yml +++ b/.github/workflows/code-checks.yml @@ -11,8 +11,6 @@ jobs: strategy: matrix: php: - - '7.4' - - '8.0' - '8.1' - '8.2' - '8.3' diff --git a/.gitignore b/.gitignore index 4901aab..a3ee6db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/vendor +/.phpunit.cache/ +/vendor/ /composer.lock -/.phpunit.result.cache diff --git a/.runConfigurations/All unit tests.run.xml b/.runConfigurations/All unit tests.run.xml index 0a179b1..1c5c127 100644 --- a/.runConfigurations/All unit tests.run.xml +++ b/.runConfigurations/All unit tests.run.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a84367..5a08844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Removed +- **BC break**: Removed support for PHP versions <= v8.0 as they are no longer + [actively supported](https://php.net/supported-versions.php) by the PHP project. ## [1.0.1] - 2025-02-08 ### Changed diff --git a/composer.json b/composer.json index 0f9bd25..6d4cfda 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,12 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "phlib/db": "^2", - "symfony/process": "^5 || ^6 || ^7" + "symfony/process": "^6 || ^7" }, "require-dev": { - "phpunit/phpunit": "^9", + "phpunit/phpunit": "^10", "symplify/easy-coding-standard": "^12" }, "autoload": { diff --git a/ecs.php b/ecs.php index c705127..86501dc 100644 --- a/ecs.php +++ b/ecs.php @@ -48,4 +48,19 @@ [ 'closure_fn_spacing' => 'none', ], + ) + + /* + * Rule from PER Coding Style 2.6: + * "If the list is split across multiple lines, then the last item MUST have a trailing comma." + */ + ->withConfiguredRule( + \PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::class, + [ + 'elements' => [ + \PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::ELEMENTS_ARGUMENTS, + \PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::ELEMENTS_ARRAYS, + \PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer::ELEMENTS_PARAMETERS, + ], + ], ); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6c17a6a..d7805a3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,10 @@ @@ -11,9 +12,9 @@ tests - + src - + diff --git a/src/Column.php b/src/Column.php index d4be608..febc2c0 100644 --- a/src/Column.php +++ b/src/Column.php @@ -6,7 +6,7 @@ use Phlib\Db\SqlFragment; -class Column +class Column implements \Stringable { use FormatterTrait; @@ -14,10 +14,6 @@ class Column private const POSITION_AFTER = 'AFTER'; - private string $name; - - private string $type; - private string $newName; private bool $unsigned; @@ -28,20 +24,18 @@ class Column private bool $nullable = true; - /** - * @var string|SqlFragment - */ - private $default; + private string|SqlFragment $default; private bool $auto; private array $position; - public function __construct(Formatter $formatter, string $name, string $type) - { + public function __construct( + Formatter $formatter, + private readonly string $name, + private string $type, + ) { $this->formatter = $formatter; - $this->name = $name; - $this->type = $type; } public function getName(): string @@ -150,7 +144,7 @@ public function toSql(): string if (!$value instanceof SqlFragment) { $value = $this->quoteValue($value); } - $definition[] = 'DEFAULT ' . (string)$value; + $definition[] = 'DEFAULT ' . $value; } if (isset($this->auto) && $this->auto === true) { diff --git a/src/Formatter/Db.php b/src/Formatter/Db.php index 01610f4..9c7b856 100644 --- a/src/Formatter/Db.php +++ b/src/Formatter/Db.php @@ -10,13 +10,11 @@ class Db implements Formatter { - private Adapter $db; - private NameMapper $nameMapper; - public function __construct(Adapter $db) - { - $this->db = $db; + public function __construct( + private readonly Adapter $db, + ) { } public function setNameMapper(NameMapper $nameMapper): void diff --git a/src/Formatter/TestFake.php b/src/Formatter/TestFake.php index 2fe449b..9a02aef 100644 --- a/src/Formatter/TestFake.php +++ b/src/Formatter/TestFake.php @@ -11,7 +11,6 @@ class TestFake implements Formatter { public function setNameMapper(NameMapper $nameMapper): void { - return; } public function tableIdentifier(string $tableIdentifier): string diff --git a/src/FormatterTrait.php b/src/FormatterTrait.php index a626ceb..62f132c 100644 --- a/src/FormatterTrait.php +++ b/src/FormatterTrait.php @@ -6,7 +6,7 @@ trait FormatterTrait { - protected Formatter $formatter; + protected readonly Formatter $formatter; protected function tableIdentifier(string $tableIdentifer): string { diff --git a/src/Index.php b/src/Index.php index 853f323..3881cfe 100644 --- a/src/Index.php +++ b/src/Index.php @@ -4,12 +4,10 @@ namespace Phlib\SchemaChange; -class Index +class Index implements \Stringable { use FormatterTrait; - private string $tableName; - private string $name; private array $columns; @@ -18,11 +16,10 @@ class Index public function __construct( Formatter $formatter, - string $tableName, - string ...$columns + private readonly string $tableName, + string ...$columns, ) { $this->formatter = $formatter; - $this->tableName = $tableName; $this->columns = $columns; } diff --git a/src/OnlineChangeRunner.php b/src/OnlineChangeRunner.php index 8a63cd2..c1c02e9 100644 --- a/src/OnlineChangeRunner.php +++ b/src/OnlineChangeRunner.php @@ -10,18 +10,15 @@ class OnlineChangeRunner { - private string $binPath; - /** - * @var \Closure { - * @return Process - * } + * @var \Closure():Process */ - private \Closure $processFactory; + private readonly \Closure $processFactory; - public function __construct(string $binPath, ?\Closure $processFactory = null) - { - $this->binPath = $binPath; + public function __construct( + private readonly string $binPath, + ?\Closure $processFactory = null, + ) { $this->processFactory = $processFactory ?? static function (...$args): Process { return new Process(...$args); }; @@ -32,7 +29,7 @@ public function execute(array $dbConfig, OnlineChange $onlineChange): void $cmd = array_merge( [$this->binPath, $this->buildDsn($dbConfig, $onlineChange->getName())], $this->getOptions($onlineChange), - ['--alter', $onlineChange->toOnlineAlter()] + ['--alter', $onlineChange->toOnlineAlter()], ); $process = $this->getProcess($cmd); @@ -80,7 +77,7 @@ private function buildDsn(array $dbConfig, string $tableName): string return $dsn; } - private function getProcess(...$args): Process + private function getProcess(array ...$args): Process { return ($this->processFactory)(...$args); } diff --git a/src/SchemaChange.php b/src/SchemaChange.php index 5861c46..00bda38 100644 --- a/src/SchemaChange.php +++ b/src/SchemaChange.php @@ -14,17 +14,14 @@ class SchemaChange { - private Adapter $db; + private readonly Formatter $formatter; - private Formatter $formatter; - - private ?OnlineChangeRunner $onlineChangeRunner; - - public function __construct(Adapter $db, OnlineChangeRunner $onlineChangeRunner = null, Formatter $formatter = null) - { - $this->db = $db; + public function __construct( + private readonly Adapter $db, + private readonly ?OnlineChangeRunner $onlineChangeRunner = null, + Formatter $formatter = null, + ) { $this->formatter = $formatter ?? new DbFormatter($this->db); - $this->onlineChangeRunner = $onlineChangeRunner; } public function mapNames(NameMapper $nameMapper): void diff --git a/src/Table.php b/src/Table.php index 2825329..6f08b6c 100644 --- a/src/Table.php +++ b/src/Table.php @@ -8,11 +8,10 @@ abstract class Table implements Change { use FormatterTrait; - protected string $table; - - public function __construct(Formatter $formatter, string $table) - { + public function __construct( + Formatter $formatter, + protected readonly string $table, + ) { $this->formatter = $formatter; - $this->table = $table; } } diff --git a/src/Table/Alter.php b/src/Table/Alter.php index e1ae8ee..f52d0b8 100644 --- a/src/Table/Alter.php +++ b/src/Table/Alter.php @@ -94,9 +94,7 @@ public function toSql(): string $tableName = $this->tableIdentifier($this->table); $ddl = "ALTER TABLE {$tableName}\n"; - $ddl .= $this->getCmds(); - - return $ddl; + return $ddl . $this->getCmds(); } public function toOnlineAlter(): string @@ -117,7 +115,7 @@ private function getCmds(): string } // add columns foreach ($this->addColumns as $column) { - $cmds[] = 'ADD ' . (string)$column; + $cmds[] = 'ADD ' . $column; } // drop column defaults foreach ($this->dropDefaultColumns as $columnName) { @@ -127,7 +125,7 @@ private function getCmds(): string // change columns foreach ($this->changeColumns as $column) { $columnName = $this->quoteIdentifier($column->getName()); - $cmds[] = 'CHANGE COLUMN ' . $columnName . ' ' . (string)$column; + $cmds[] = 'CHANGE COLUMN ' . $columnName . ' ' . $column; } // remove fields foreach ($this->removeColumns as $column) { @@ -143,7 +141,7 @@ private function getCmds(): string } // add indexes (key) foreach ($this->addIndexes as $index) { - $cmds[] = 'ADD ' . (string)$index; + $cmds[] = 'ADD ' . $index; } // remove indexes (key) foreach ($this->removeIndexes as $index) { diff --git a/tests/Formatter/DbTest.php b/tests/Formatter/DbTest.php index 3450ae5..6b78380 100644 --- a/tests/Formatter/DbTest.php +++ b/tests/Formatter/DbTest.php @@ -12,15 +12,9 @@ class DbTest extends TestCase { - /** - * @var Adapter|MockObject - */ - private $db; - - /** - * @var Adapter\QuoteHandler|MockObject - */ - private $quoter; + private Adapter&MockObject $db; + + private Adapter\QuoteHandler&MockObject $quoter; protected function setUp(): void {