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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/Cache/SchemaCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Driver/Pdo/AbstractPdoTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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):
*
Expand Down Expand Up @@ -79,7 +80,7 @@
} else {
$this->logger?->log(
LogLevel::DEBUG,
'Transaction not started: nested transaction not supported ' . __METHOD__,

Check warning on line 83 in src/Driver/Pdo/AbstractPdoTransaction.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ $this->logger?->log(LogLevel::DEBUG, 'Set savepoint ' . $this->level . ' ' . __METHOD__, ['type' => LogType::TRANSACTION]); $this->createSavepoint('LEVEL' . $this->level); } else { - $this->logger?->log(LogLevel::DEBUG, 'Transaction not started: nested transaction not supported ' . __METHOD__, ['type' => LogType::TRANSACTION]); + $this->logger?->log(LogLevel::DEBUG, 'Transaction not started: nested transaction not supported ', ['type' => LogType::TRANSACTION]); throw new NotSupportedException('Transaction not started: nested transaction not supported.'); } $this->level++;

Check warning on line 83 in src/Driver/Pdo/AbstractPdoTransaction.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Escaped Mutant for Mutator "Concat": @@ @@ $this->logger?->log(LogLevel::DEBUG, 'Set savepoint ' . $this->level . ' ' . __METHOD__, ['type' => LogType::TRANSACTION]); $this->createSavepoint('LEVEL' . $this->level); } else { - $this->logger?->log(LogLevel::DEBUG, 'Transaction not started: nested transaction not supported ' . __METHOD__, ['type' => LogType::TRANSACTION]); + $this->logger?->log(LogLevel::DEBUG, __METHOD__ . 'Transaction not started: nested transaction not supported ', ['type' => LogType::TRANSACTION]); throw new NotSupportedException('Transaction not started: nested transaction not supported.'); } $this->level++;
['type' => LogType::TRANSACTION],
);

Expand Down Expand Up @@ -180,9 +181,9 @@
throw new Exception('Failed to set isolation level: transaction was inactive.');
}

$this->logger?->log(

Check warning on line 184 in src/Driver/Pdo/AbstractPdoTransaction.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ if (!$this->isActive()) { throw new Exception('Failed to set isolation level: transaction was inactive.'); } - $this->logger?->log(LogLevel::DEBUG, 'Setting transaction isolation level to ' . $this->level . ' ' . __METHOD__, ['type' => LogType::TRANSACTION]); + $this->setTransactionIsolationLevel($level); } public function createSavepoint(string $name): void
LogLevel::DEBUG,
'Setting transaction isolation level to ' . $this->level . ' ' . __METHOD__,

Check warning on line 186 in src/Driver/Pdo/AbstractPdoTransaction.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ if (!$this->isActive()) { throw new Exception('Failed to set isolation level: transaction was inactive.'); } - $this->logger?->log(LogLevel::DEBUG, 'Setting transaction isolation level to ' . $this->level . ' ' . __METHOD__, ['type' => LogType::TRANSACTION]); + $this->logger?->log(LogLevel::DEBUG, 'Setting transaction isolation level to ' . $this->level . ' ', ['type' => LogType::TRANSACTION]); $this->setTransactionIsolationLevel($level); } public function createSavepoint(string $name): void

Check warning on line 186 in src/Driver/Pdo/AbstractPdoTransaction.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ if (!$this->isActive()) { throw new Exception('Failed to set isolation level: transaction was inactive.'); } - $this->logger?->log(LogLevel::DEBUG, 'Setting transaction isolation level to ' . $this->level . ' ' . __METHOD__, ['type' => LogType::TRANSACTION]); + $this->logger?->log(LogLevel::DEBUG, 'Setting transaction isolation level to ' . $this->level . __METHOD__, ['type' => LogType::TRANSACTION]); $this->setTransactionIsolationLevel($level); } public function createSavepoint(string $name): void

Check warning on line 186 in src/Driver/Pdo/AbstractPdoTransaction.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Escaped Mutant for Mutator "Concat": @@ @@ if (!$this->isActive()) { throw new Exception('Failed to set isolation level: transaction was inactive.'); } - $this->logger?->log(LogLevel::DEBUG, 'Setting transaction isolation level to ' . $this->level . ' ' . __METHOD__, ['type' => LogType::TRANSACTION]); + $this->logger?->log(LogLevel::DEBUG, $this->level . 'Setting transaction isolation level to ' . ' ' . __METHOD__, ['type' => LogType::TRANSACTION]); $this->setTransactionIsolationLevel($level); } public function createSavepoint(string $name): void
['type' => LogType::TRANSACTION],
);
$this->setTransactionIsolationLevel($level);
Expand Down Expand Up @@ -212,6 +213,6 @@
*/
protected function setTransactionIsolationLevel(string $level): void
{
$this->db->createCommand("SET TRANSACTION ISOLATION LEVEL $level")->execute();

Check warning on line 216 in src/Driver/Pdo/AbstractPdoTransaction.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ */ protected function setTransactionIsolationLevel(string $level): void { - $this->db->createCommand("SET TRANSACTION ISOLATION LEVEL {$level}")->execute(); + } }
}
}
5 changes: 4 additions & 1 deletion src/Exception/ConvertException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/Profiler/Context/AbstractContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 4 additions & 4 deletions src/Profiler/Context/CommandContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Profiler/ProfilerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 3 additions & 1 deletion src/Query/QueryExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/QueryBuilder/AbstractDQLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ abstract class AbstractDQLQueryBuilder implements DQLQueryBuilderInterface

public function __construct(
protected QueryBuilderInterface $queryBuilder,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected QueryBuilderInterface $queryBuilder,
protected readonly QueryBuilderInterface $queryBuilder,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks BC.

private QuoterInterface $quoter,
private readonly QuoterInterface $quoter,
) {
$this->expressionBuilders = $this->defaultExpressionBuilders();
$this->conditionClasses = $this->defaultConditionClasses();
Expand Down
8 changes: 4 additions & 4 deletions src/QueryBuilder/AbstractQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private AbstractDMLQueryBuilder $dmlBuilder,
private readonly AbstractDMLQueryBuilder $dmlBuilder,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is not readonly. See withTypecasting() method.

private AbstractDQLQueryBuilder $dqlBuilder,
private AbstractColumnDefinitionBuilder $columnDefinitionBuilder,
private readonly AbstractDQLQueryBuilder $dqlBuilder,
private readonly AbstractColumnDefinitionBuilder $columnDefinitionBuilder,
) {}

public function addCheck(string $table, string $name, string $expression): string
Expand Down
5 changes: 4 additions & 1 deletion src/Schema/AbstractSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected ConnectionInterface $db,
protected readonly ConnectionInterface $db,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks BC.

private readonly SchemaCache $schemaCache,
) {}

public function getDefaultSchema(): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/Quoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '',
) {}

Expand Down
Loading