From aa261e13332eaa3ca4a23caba3d085e3cbb07f9c Mon Sep 17 00:00:00 2001
From: Chris Minett <1084019+chrisminett@users.noreply.github.com>
Date: Sat, 8 Feb 2025 06:33:19 +0000
Subject: [PATCH 1/4] Drop support for PHP <= v8.0
---
.github/workflows/code-checks.yml | 2 --
CHANGELOG.md | 3 +++
composer.json | 4 ++--
src/Column.php | 9 +++------
src/Formatter/TestFake.php | 1 -
src/Index.php | 2 +-
src/OnlineChangeRunner.php | 2 +-
src/Table/Alter.php | 10 ++++------
8 files changed, 14 insertions(+), 19 deletions(-)
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/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..6f7b3a0 100644
--- a/composer.json
+++ b/composer.json
@@ -13,9 +13,9 @@
}
],
"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",
diff --git a/src/Column.php b/src/Column.php
index d4be608..49182d4 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;
@@ -28,10 +28,7 @@ class Column
private bool $nullable = true;
- /**
- * @var string|SqlFragment
- */
- private $default;
+ private string|SqlFragment $default;
private bool $auto;
@@ -150,7 +147,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/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/Index.php b/src/Index.php
index 853f323..b3b44cb 100644
--- a/src/Index.php
+++ b/src/Index.php
@@ -4,7 +4,7 @@
namespace Phlib\SchemaChange;
-class Index
+class Index implements \Stringable
{
use FormatterTrait;
diff --git a/src/OnlineChangeRunner.php b/src/OnlineChangeRunner.php
index 8a63cd2..c2faab3 100644
--- a/src/OnlineChangeRunner.php
+++ b/src/OnlineChangeRunner.php
@@ -80,7 +80,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/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) {
From 89279499c1d003f299f142de07a9fd7c42c1855a Mon Sep 17 00:00:00 2001
From: Chris Minett <1084019+chrisminett@users.noreply.github.com>
Date: Sat, 8 Feb 2025 06:53:57 +0000
Subject: [PATCH 2/4] Update ECS
---
ecs.php | 15 +++++++++++++++
src/Index.php | 2 +-
src/OnlineChangeRunner.php | 2 +-
3 files changed, 17 insertions(+), 2 deletions(-)
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/src/Index.php b/src/Index.php
index b3b44cb..9e87abf 100644
--- a/src/Index.php
+++ b/src/Index.php
@@ -19,7 +19,7 @@ class Index implements \Stringable
public function __construct(
Formatter $formatter,
string $tableName,
- string ...$columns
+ string ...$columns,
) {
$this->formatter = $formatter;
$this->tableName = $tableName;
diff --git a/src/OnlineChangeRunner.php b/src/OnlineChangeRunner.php
index c2faab3..0d33d66 100644
--- a/src/OnlineChangeRunner.php
+++ b/src/OnlineChangeRunner.php
@@ -32,7 +32,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);
From 15b5ef35ab29384687da6dec21226daa77ff6233 Mon Sep 17 00:00:00 2001
From: Chris Minett <1084019+chrisminett@users.noreply.github.com>
Date: Sat, 8 Feb 2025 06:53:37 +0000
Subject: [PATCH 3/4] Use constructor property promotion
---
src/Column.php | 13 +++++--------
src/Formatter/Db.php | 8 +++-----
src/FormatterTrait.php | 2 +-
src/Index.php | 5 +----
src/OnlineChangeRunner.php | 15 ++++++---------
src/SchemaChange.php | 15 ++++++---------
src/Table.php | 9 ++++-----
7 files changed, 26 insertions(+), 41 deletions(-)
diff --git a/src/Column.php b/src/Column.php
index 49182d4..febc2c0 100644
--- a/src/Column.php
+++ b/src/Column.php
@@ -14,10 +14,6 @@ class Column implements \Stringable
private const POSITION_AFTER = 'AFTER';
- private string $name;
-
- private string $type;
-
private string $newName;
private bool $unsigned;
@@ -34,11 +30,12 @@ class Column implements \Stringable
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
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/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 9e87abf..3881cfe 100644
--- a/src/Index.php
+++ b/src/Index.php
@@ -8,8 +8,6 @@ class Index implements \Stringable
{
use FormatterTrait;
- private string $tableName;
-
private string $name;
private array $columns;
@@ -18,11 +16,10 @@ class Index implements \Stringable
public function __construct(
Formatter $formatter,
- string $tableName,
+ 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 0d33d66..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);
};
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;
}
}
From 58477b1216eacdbe1cb607b67fb1f046066551d7 Mon Sep 17 00:00:00 2001
From: Chris Minett <1084019+chrisminett@users.noreply.github.com>
Date: Sun, 9 Feb 2025 08:27:28 +0000
Subject: [PATCH 4/4] Upgrade PHPUnit to v10
---
.gitignore | 4 ++--
.runConfigurations/All unit tests.run.xml | 2 +-
composer.json | 2 +-
phpunit.xml.dist | 7 ++++---
tests/Formatter/DbTest.php | 12 +++---------
5 files changed, 11 insertions(+), 16 deletions(-)
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/composer.json b/composer.json
index 6f7b3a0..6d4cfda 100644
--- a/composer.json
+++ b/composer.json
@@ -18,7 +18,7 @@
"symfony/process": "^6 || ^7"
},
"require-dev": {
- "phpunit/phpunit": "^9",
+ "phpunit/phpunit": "^10",
"symplify/easy-coding-standard": "^12"
},
"autoload": {
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/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
{