diff --git a/CHANGELOG.md b/CHANGELOG.md index 0345f4df3..a0d7d3c20 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: Explicitly mark readonly properties (@vjik) - Enh #1156: Remove unnecessary files from Composer package (@mspirkov) ## 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. 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..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 \Yiisoft\Db\Connection\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): * 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/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 { 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 = '', ) {}