From 5b37e4adadea57c7ce4b144ce681044d005653d2 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 30 Jan 2026 16:20:38 +0300 Subject: [PATCH 1/7] Mark `$psrCache` property in `SchemaCache` as readonly --- CHANGELOG.md | 1 + src/Cache/SchemaCache.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1941284e..f8cabe1e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ brackets `{{%table}}` (@batyrmastyr) - Enh #1145, #1148: Explicitly import classes, functions, and constants in "use" section (@mspirkov) - Enh #1148: Add `declare(strict_types=1)` to `Yiisoft\Db\Constant\ColumnInfoSource` (@mspirkov) +- Enh #1158: Mark `$psrCache` property in `SchemaCache` as readonly (@vjik) ## 2.0.0 December 05, 2025 diff --git a/src/Cache/SchemaCache.php b/src/Cache/SchemaCache.php index 0a084131f..72b79e46f 100644 --- a/src/Cache/SchemaCache.php +++ b/src/Cache/SchemaCache.php @@ -42,7 +42,9 @@ final class SchemaCache * * @link https://www.php-fig.org/psr/psr-16/ */ - public function __construct(private CacheInterface $psrCache) {} + public function __construct( + private readonly CacheInterface $psrCache, + ) {} /** * Remove a value with the specified key from cache. From 248cfcd131ec82ccb1c6305b1eff1c49998f9cd2 Mon Sep 17 00:00:00 2001 From: vjik <525501+vjik@users.noreply.github.com> Date: Fri, 30 Jan 2026 13:21:38 +0000 Subject: [PATCH 2/7] Apply PHP CS Fixer and Rector changes (CI) --- src/Command/AbstractCommand.php | 2 +- src/Driver/Pdo/AbstractPdoTransaction.php | 3 ++- src/Profiler/ProfilerInterface.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 84cf33dca..c96c6e9d9 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -28,7 +28,7 @@ /** * Represents an SQL statement to execute in a database. * - * It's usually created by calling {@see \Yiisoft\Db\Connection\ConnectionInterface::createCommand()}. + * It's usually created by calling {@see ConnectionInterface::createCommand()}. * * You can get the SQL statement it represents via the {@see getSql()} method. * diff --git a/src/Driver/Pdo/AbstractPdoTransaction.php b/src/Driver/Pdo/AbstractPdoTransaction.php index 53b79fae8..b5464e353 100644 --- a/src/Driver/Pdo/AbstractPdoTransaction.php +++ b/src/Driver/Pdo/AbstractPdoTransaction.php @@ -12,13 +12,14 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Transaction\TransactionInterface; +use Yiisoft\Db\Connection\AbstractConnectionAbstractConnection; /** * Represents a DB transaction. * * A transaction is a set of SQL statements that must either all succeed or all fail. * - * It's usually created by calling {@see \Yiisoft\Db\Connection\AbstractConnectionAbstractConnection::beginTransaction()}. + * It's usually created by calling {@see AbstractConnectionAbstractConnection::beginTransaction()}. * * The following code is a typical example of using transactions (note that some DBMS may not support transactions): * diff --git a/src/Profiler/ProfilerInterface.php b/src/Profiler/ProfilerInterface.php index c55188086..56936485e 100644 --- a/src/Profiler/ProfilerInterface.php +++ b/src/Profiler/ProfilerInterface.php @@ -7,7 +7,7 @@ /** * Interface-decorator to work with `yiisoft\profiler` or another profiler. * - * @see \Yiisoft\Db\Profiler\ProfilerAwareInterface::setProfiler() + * @see ProfilerAwareInterface::setProfiler() */ interface ProfilerInterface { From 2187c7c2dfc849d4e186ad8cc665661380260bc7 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 30 Jan 2026 23:08:53 +0300 Subject: [PATCH 3/7] Update src/Driver/Pdo/AbstractPdoTransaction.php Co-authored-by: Sergei Tigrov --- src/Driver/Pdo/AbstractPdoTransaction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Driver/Pdo/AbstractPdoTransaction.php b/src/Driver/Pdo/AbstractPdoTransaction.php index b5464e353..2458b94dc 100644 --- a/src/Driver/Pdo/AbstractPdoTransaction.php +++ b/src/Driver/Pdo/AbstractPdoTransaction.php @@ -12,7 +12,7 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Transaction\TransactionInterface; -use Yiisoft\Db\Connection\AbstractConnectionAbstractConnection; +use Yiisoft\Db\Connection\ConnectionInterface; /** * Represents a DB transaction. From 4514dd88e5915a438618a6290f0d44912b3ee8be Mon Sep 17 00:00:00 2001 From: vjik <525501+vjik@users.noreply.github.com> Date: Fri, 30 Jan 2026 20:09:33 +0000 Subject: [PATCH 4/7] Apply PHP CS Fixer and Rector changes (CI) --- src/Driver/Pdo/AbstractPdoTransaction.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Driver/Pdo/AbstractPdoTransaction.php b/src/Driver/Pdo/AbstractPdoTransaction.php index 2458b94dc..068e9bfbc 100644 --- a/src/Driver/Pdo/AbstractPdoTransaction.php +++ b/src/Driver/Pdo/AbstractPdoTransaction.php @@ -12,7 +12,6 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Transaction\TransactionInterface; -use Yiisoft\Db\Connection\ConnectionInterface; /** * Represents a DB transaction. From 890f980e3ee50e826624f9577960c6e5923a0810 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 1 Feb 2026 17:56:09 +0300 Subject: [PATCH 5/7] Explicitly mark readonly properties --- CHANGELOG.md | 2 +- src/Exception/ConvertException.php | 5 ++++- src/Profiler/Context/AbstractContext.php | 4 +++- src/Profiler/Context/CommandContext.php | 8 ++++---- src/Query/QueryExpressionBuilder.php | 4 +++- src/QueryBuilder/AbstractDQLQueryBuilder.php | 2 +- src/QueryBuilder/AbstractQueryBuilder.php | 8 ++++---- src/Schema/AbstractSchema.php | 5 ++++- src/Schema/Quoter.php | 4 ++-- 9 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8cabe1e2..5a34040e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ brackets `{{%table}}` (@batyrmastyr) - Enh #1145, #1148: Explicitly import classes, functions, and constants in "use" section (@mspirkov) - Enh #1148: Add `declare(strict_types=1)` to `Yiisoft\Db\Constant\ColumnInfoSource` (@mspirkov) -- Enh #1158: Mark `$psrCache` property in `SchemaCache` as readonly (@vjik) +- Enh #1158: Explicitly mark readonly properties (@vjik) ## 2.0.0 December 05, 2025 diff --git a/src/Exception/ConvertException.php b/src/Exception/ConvertException.php index e64271c25..b4d00fe64 100644 --- a/src/Exception/ConvertException.php +++ b/src/Exception/ConvertException.php @@ -20,7 +20,10 @@ final class ConvertException private const MGS_INTEGRITY_EXCEPTION_2 = 'ORA-00001: unique constraint'; private const MSG_INTEGRITY_EXCEPTION_3 = 'SQLSTATE[HY'; - public function __construct(private \Exception $e, private string $rawSql) {} + public function __construct( + private readonly \Exception $e, + private readonly string $rawSql, + ) {} /** * Converts an exception into a more specific one. diff --git a/src/Profiler/Context/AbstractContext.php b/src/Profiler/Context/AbstractContext.php index 048bf7f96..53230f0d4 100644 --- a/src/Profiler/Context/AbstractContext.php +++ b/src/Profiler/Context/AbstractContext.php @@ -14,7 +14,9 @@ abstract class AbstractContext implements ContextInterface private ?Throwable $exception = null; - public function __construct(private string $method) {} + public function __construct( + private readonly string $method, + ) {} public function setException(Throwable $e): static { diff --git a/src/Profiler/Context/CommandContext.php b/src/Profiler/Context/CommandContext.php index b5e4a9cb3..dcd16b0dd 100644 --- a/src/Profiler/Context/CommandContext.php +++ b/src/Profiler/Context/CommandContext.php @@ -11,10 +11,10 @@ final class CommandContext extends AbstractContext private const PARAMS = 'params'; public function __construct( - private string $method, - private string $logContext, - private string $sql, - private array $params, + private readonly string $method, + private readonly string $logContext, + private readonly string $sql, + private readonly array $params, ) { parent::__construct($this->method); } diff --git a/src/Query/QueryExpressionBuilder.php b/src/Query/QueryExpressionBuilder.php index 91734e7b2..209c5d84a 100644 --- a/src/Query/QueryExpressionBuilder.php +++ b/src/Query/QueryExpressionBuilder.php @@ -21,7 +21,9 @@ */ final class QueryExpressionBuilder implements ExpressionBuilderInterface { - public function __construct(private QueryBuilderInterface $queryBuilder) {} + public function __construct( + private readonly QueryBuilderInterface $queryBuilder, + ) {} /** * @param QueryInterface $expression diff --git a/src/QueryBuilder/AbstractDQLQueryBuilder.php b/src/QueryBuilder/AbstractDQLQueryBuilder.php index 3eae9b427..d55c7a624 100644 --- a/src/QueryBuilder/AbstractDQLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDQLQueryBuilder.php @@ -113,7 +113,7 @@ abstract class AbstractDQLQueryBuilder implements DQLQueryBuilderInterface public function __construct( protected QueryBuilderInterface $queryBuilder, - private QuoterInterface $quoter, + private readonly QuoterInterface $quoter, ) { $this->expressionBuilders = $this->defaultExpressionBuilders(); $this->conditionClasses = $this->defaultConditionClasses(); diff --git a/src/QueryBuilder/AbstractQueryBuilder.php b/src/QueryBuilder/AbstractQueryBuilder.php index 34db88f17..2d7082ef3 100644 --- a/src/QueryBuilder/AbstractQueryBuilder.php +++ b/src/QueryBuilder/AbstractQueryBuilder.php @@ -77,11 +77,11 @@ abstract class AbstractQueryBuilder implements QueryBuilderInterface protected array $typeMap = []; public function __construct( - private ConnectionInterface $db, - private AbstractDDLQueryBuilder $ddlBuilder, + private readonly ConnectionInterface $db, + private readonly AbstractDDLQueryBuilder $ddlBuilder, private AbstractDMLQueryBuilder $dmlBuilder, - private AbstractDQLQueryBuilder $dqlBuilder, - private AbstractColumnDefinitionBuilder $columnDefinitionBuilder, + private readonly AbstractDQLQueryBuilder $dqlBuilder, + private readonly AbstractColumnDefinitionBuilder $columnDefinitionBuilder, ) {} public function addCheck(string $table, string $name, string $expression): string diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index 64c0727d3..87cbe76a7 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -53,7 +53,10 @@ abstract class AbstractSchema implements SchemaInterface /** @var (Check[]|DefaultValue[]|ForeignKey[]|Index|Index[]|TableSchemaInterface|null)[][] */ private array $tableMetadata = []; - public function __construct(protected ConnectionInterface $db, private SchemaCache $schemaCache) {} + public function __construct( + protected ConnectionInterface $db, + private readonly SchemaCache $schemaCache, + ) {} public function getDefaultSchema(): string { diff --git a/src/Schema/Quoter.php b/src/Schema/Quoter.php index f1bf78367..b25d24a52 100644 --- a/src/Schema/Quoter.php +++ b/src/Schema/Quoter.php @@ -38,9 +38,9 @@ class Quoter implements QuoterInterface { public function __construct( /** @psalm-var string[]|string */ - private array|string $columnQuoteCharacter, + private readonly array|string $columnQuoteCharacter, /** @psalm-var string[]|string */ - private array|string $tableQuoteCharacter, + private readonly array|string $tableQuoteCharacter, private string $tablePrefix = '', ) {} From d470ee0b884cf7aa2170d717692017f6472676a6 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 1 Feb 2026 17:57:48 +0300 Subject: [PATCH 6/7] fix --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de3b3a0dc..a0d7d3c20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,6 @@ - Enh #1145, #1148: Explicitly import classes, functions, and constants in "use" section (@mspirkov) - Enh #1148: Add `declare(strict_types=1)` to `Yiisoft\Db\Constant\ColumnInfoSource` (@mspirkov) - Enh #1158: Explicitly mark readonly properties (@vjik) -- Enh #1158: Mark `$psrCache` property in `SchemaCache` as readonly (@vjik) - Enh #1156: Remove unnecessary files from Composer package (@mspirkov) ## 2.0.0 December 05, 2025 From 339f90d8c1c84a2ac99742cf9b9dd0fda28dbb76 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 1 Feb 2026 17:58:54 +0300 Subject: [PATCH 7/7] fix --- src/Driver/Pdo/AbstractPdoTransaction.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Driver/Pdo/AbstractPdoTransaction.php b/src/Driver/Pdo/AbstractPdoTransaction.php index 068e9bfbc..02bbb3799 100644 --- a/src/Driver/Pdo/AbstractPdoTransaction.php +++ b/src/Driver/Pdo/AbstractPdoTransaction.php @@ -8,6 +8,7 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\LogLevel; use Throwable; +use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; @@ -18,7 +19,7 @@ * * A transaction is a set of SQL statements that must either all succeed or all fail. * - * It's usually created by calling {@see AbstractConnectionAbstractConnection::beginTransaction()}. + * It's usually created by calling {@see ConnectionInterface::beginTransaction()}. * * The following code is a typical example of using transactions (note that some DBMS may not support transactions): *