diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8aa7232d2..841e41e5b 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -19,5 +19,13 @@ 'no_unused_imports' => true, 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], + 'fully_qualified_strict_types' => [ + 'import_symbols' => true + ], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => true, + ], ]) ->setFinder($finder); diff --git a/CHANGELOG.md b/CHANGELOG.md index de0a23124..7e623c632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Bug #1127: Fix `AbstractSchema::hasTable()` and `AbstractSchema::hasView()` methods to support names quoted with curly brackets `{{%table}}` (@batyrmastyr) +- Enh #1145: Explicitly import classes, functions, and constants in "use" section (@mspirkov) ## 2.0.0 December 05, 2025 diff --git a/src/Cache/SchemaCache.php b/src/Cache/SchemaCache.php index 8f41f194b..0a084131f 100644 --- a/src/Cache/SchemaCache.php +++ b/src/Cache/SchemaCache.php @@ -9,6 +9,7 @@ use Psr\SimpleCache\InvalidArgumentException; use RuntimeException; use Yiisoft\Db\Exception\PsrInvalidArgumentException; +use Yiisoft\Db\Schema\AbstractSchema; use function in_array; use function is_int; @@ -22,13 +23,13 @@ /** * Implements a cache for the database schema information. * - * The {@see \Yiisoft\Db\Schema\AbstractSchema} retrieves information about the database schema from the database server - * and stores it in the cache for faster access. When the {@see \Yiisoft\Db\Schema\AbstractSchema} needs to retrieve + * The {@see AbstractSchema} retrieves information about the database schema from the database server + * and stores it in the cache for faster access. When the {@see AbstractSchema} needs to retrieve * information about the database schema, it first checks the cache using {@see SchemaCache}. If the information is * not in the cache, the Schema retrieves it from the database server and stores it in the cache using the * {@see SchemaCache}. * - * {@see \Yiisoft\Db\Schema\AbstractSchema} uses this implementation to cache table metadata. + * {@see AbstractSchema} uses this implementation to cache table metadata. */ final class SchemaCache { diff --git a/src/Driver/Pdo/AbstractPdoCommand.php b/src/Driver/Pdo/AbstractPdoCommand.php index 9ac906df8..d29d16c93 100644 --- a/src/Driver/Pdo/AbstractPdoCommand.php +++ b/src/Driver/Pdo/AbstractPdoCommand.php @@ -62,7 +62,7 @@ public function __construct(PdoConnectionInterface $db) } /** - * This method mainly sets {@see pdoStatement} to be `null`. + * This method mainly sets {@see PDOStatement} to be `null`. */ public function cancel(): void { @@ -165,7 +165,7 @@ public function prepare(?bool $forRead = null): void /** * Binds pending parameters registered via {@see bindValue()} and {@see bindValues()}. * - * Note that this method requires an active {@see pdoStatement}. + * Note that this method requires an active {@see PDOStatement}. */ protected function bindPendingParams(): void { diff --git a/src/Driver/Pdo/PdoDataReader.php b/src/Driver/Pdo/PdoDataReader.php index fe867dd4f..9c802e2d5 100644 --- a/src/Driver/Pdo/PdoDataReader.php +++ b/src/Driver/Pdo/PdoDataReader.php @@ -13,6 +13,7 @@ use Yiisoft\Db\Query\DataReaderInterface; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\Schema\Column\ColumnInterface; +use Yiisoft\Db\Command\AbstractCommand; use function is_string; @@ -21,7 +22,7 @@ * * A data reader is an object that can be used to read a forward-only stream of rows from a database. * - * It's typically used in combination with a command object, such as a {@see \Yiisoft\Db\Command\AbstractCommand}, + * It's typically used in combination with a command object, such as a {@see AbstractCommand}, * to execute a SELECT statement and read the results. * * The class provides methods for accessing the data returned by the query. diff --git a/src/Exception/PsrInvalidArgumentException.php b/src/Exception/PsrInvalidArgumentException.php index 712e072ff..6779b152f 100644 --- a/src/Exception/PsrInvalidArgumentException.php +++ b/src/Exception/PsrInvalidArgumentException.php @@ -4,7 +4,9 @@ namespace Yiisoft\Db\Exception; +use Psr\SimpleCache\InvalidArgumentException; + /** * Represents an exception that's caused by invalid operations of cache. */ -final class PsrInvalidArgumentException extends Exception implements \Psr\SimpleCache\InvalidArgumentException {} +final class PsrInvalidArgumentException extends Exception implements InvalidArgumentException {} diff --git a/src/Expression/Expression.php b/src/Expression/Expression.php index c4c893180..59cff82b2 100644 --- a/src/Expression/Expression.php +++ b/src/Expression/Expression.php @@ -6,6 +6,7 @@ use Stringable; use Yiisoft\Db\Connection\ConnectionInterface; +use Yiisoft\Db\Query\QueryInterface; /** * Represents a DB expression that doesn't need escaping or quoting. @@ -22,7 +23,7 @@ * ``` * * Expression objects are mainly created for passing raw SQL expressions to methods of - * {@see \Yiisoft\Db\Query\QueryInterface} and related classes. + * {@see QueryInterface} and related classes. * * @psalm-import-type ParamsType from ConnectionInterface */ diff --git a/src/Query/Query.php b/src/Query/Query.php index 55b7e4e37..7b183f9b8 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -16,6 +16,7 @@ use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Helper\DbArrayHelper; use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; +use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder; use function array_column; use function array_combine; @@ -71,7 +72,7 @@ * $rows = $command->queryAll(); * ``` * - * Query internally uses the {@see \Yiisoft\Db\QueryBuilder\AbstractQueryBuilder} class to generate the SQL statement. + * Query internally uses the {@see AbstractQueryBuilder} class to generate the SQL statement. * * @psalm-import-type SelectValue from QueryPartsInterface * @psalm-import-type IndexBy from QueryInterface diff --git a/src/Query/QueryExpressionBuilder.php b/src/Query/QueryExpressionBuilder.php index 2f1e9639f..91734e7b2 100644 --- a/src/Query/QueryExpressionBuilder.php +++ b/src/Query/QueryExpressionBuilder.php @@ -11,9 +11,10 @@ use Yiisoft\Db\Expression\ExpressionBuilderInterface; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; +use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder; /** - * Used internally to build a {@see Query} object using unified {@see \Yiisoft\Db\QueryBuilder\AbstractQueryBuilder} + * Used internally to build a {@see Query} object using unified {@see AbstractQueryBuilder} * expression building interface. * * @implements ExpressionBuilderInterface diff --git a/src/QueryBuilder/Condition/ConditionInterface.php b/src/QueryBuilder/Condition/ConditionInterface.php index f9b2813bb..83db1fe3b 100644 --- a/src/QueryBuilder/Condition/ConditionInterface.php +++ b/src/QueryBuilder/Condition/ConditionInterface.php @@ -6,9 +6,10 @@ use InvalidArgumentException; use Yiisoft\Db\Expression\ExpressionInterface; +use Yiisoft\Db\QueryBuilder\QueryBuilder; /** - * Should be implemented by classes that represent a condition in the {@see \Yiisoft\Db\QueryBuilder\QueryBuilder}. + * Should be implemented by classes that represent a condition in the {@see QueryBuilder}. */ interface ConditionInterface extends ExpressionInterface { diff --git a/src/Schema/Column/JsonColumn.php b/src/Schema/Column/JsonColumn.php index 2a2dddd23..b5693eebf 100644 --- a/src/Schema/Column/JsonColumn.php +++ b/src/Schema/Column/JsonColumn.php @@ -4,6 +4,8 @@ namespace Yiisoft\Db\Schema\Column; +use JsonException; + use function is_string; use function json_decode; @@ -17,7 +19,7 @@ final class JsonColumn extends AbstractJsonColumn { /** - * @throws \JsonException + * @throws JsonException */ public function phpTypecast(mixed $value): mixed { diff --git a/src/Schema/Quoter.php b/src/Schema/Quoter.php index dff1c14f0..f1bf78367 100644 --- a/src/Schema/Quoter.php +++ b/src/Schema/Quoter.php @@ -6,6 +6,8 @@ use InvalidArgumentException; use Yiisoft\Db\Expression\ExpressionInterface; +use Yiisoft\Db\Command\AbstractCommand; +use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder; use function addcslashes; use function array_map; @@ -27,9 +29,9 @@ * It provides a set of methods for quoting different types of names, such as table names, column names, and schema * names. * - * The Quoter class is used by {@see \Yiisoft\Db\QueryBuilder\AbstractQueryBuilder} to quote names. + * The Quoter class is used by {@see AbstractQueryBuilder} to quote names. * - * It's also used by {@see \Yiisoft\Db\Command\AbstractCommand} to quote names in SQL statements before passing them to + * It's also used by {@see AbstractCommand} to quote names in SQL statements before passing them to * database servers. */ class Quoter implements QuoterInterface diff --git a/src/Transaction/TransactionInterface.php b/src/Transaction/TransactionInterface.php index 92f171e0a..dbadbc493 100644 --- a/src/Transaction/TransactionInterface.php +++ b/src/Transaction/TransactionInterface.php @@ -8,6 +8,7 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; +use Yiisoft\Db\Connection\ConnectionInterface; /** * Defines the interface for a database transaction. @@ -69,7 +70,7 @@ interface TransactionInterface * * @throws Exception * @throws Throwable If DB connection fails or the current transaction is active. - * @throws InvalidConfigException If {@see \Yiisoft\Db\Connection\ConnectionInterface} is `null` or invalid. + * @throws InvalidConfigException If {@see ConnectionInterface} is `null` or invalid. * @throws NotSupportedException If the DBMS doesn't support nested transactions or the transaction is active. */ public function begin(?string $isolationLevel = null): void; diff --git a/tests/Db/Driver/Pdo/PdoDriverTest.php b/tests/Db/Driver/Pdo/PdoDriverTest.php index a9b8fa8e3..f8898b563 100644 --- a/tests/Db/Driver/Pdo/PdoDriverTest.php +++ b/tests/Db/Driver/Pdo/PdoDriverTest.php @@ -8,6 +8,8 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Db\Tests\Support\Assert; use Yiisoft\Db\Tests\Support\Stub\StubPdoDriver; +use SensitiveParameterValue; +use TypeError; /** * @group db @@ -71,14 +73,14 @@ public function testSensitiveParameter(): void $dsn = 'sqlite::memory:'; try { new StubPdoDriver($dsn, password: null); - } catch (\TypeError $e) { - $this->assertTrue($e->getTrace()[0]['args'][2] instanceof \SensitiveParameterValue); + } catch (TypeError $e) { + $this->assertTrue($e->getTrace()[0]['args'][2] instanceof SensitiveParameterValue); } $pdoDriver = new StubPdoDriver($dsn); try { $pdoDriver->password(null); - } catch (\TypeError $e) { - $this->assertTrue($e->getTrace()[0]['args'][0] instanceof \SensitiveParameterValue); + } catch (TypeError $e) { + $this->assertTrue($e->getTrace()[0]['args'][0] instanceof SensitiveParameterValue); } } } diff --git a/tests/Db/Helper/DbArrayHelperTest.php b/tests/Db/Helper/DbArrayHelperTest.php index 04bacff1f..f3d87cc08 100644 --- a/tests/Db/Helper/DbArrayHelperTest.php +++ b/tests/Db/Helper/DbArrayHelperTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Db\Helper\DbArrayHelper; use Yiisoft\Db\Tests\Provider\DbArrayHelperProvider; +use Exception; /** * @group db @@ -60,7 +61,7 @@ public function testArrangeWithNonExistingKey(): void set_error_handler(static function (int $errno, string $errstr) { restore_error_handler(); - throw new \Exception('E_WARNING: ' . $errstr, $errno); + throw new Exception('E_WARNING: ' . $errstr, $errno); }, E_WARNING); $this->expectExceptionMessage('E_WARNING: Undefined array key "non-existing-key"'); diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 6e89d3b62..3c98ebb37 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -1890,7 +1890,7 @@ public static function multiOperandFunctionBuilder(): iterable ]; yield 'Greatest with 4 operands' => [ Greatest::class, - static fn(Connectioninterface $db) => [1, 1.5, '(1 + 2)', $db->select(10)], + static fn(ConnectionInterface $db) => [1, 1.5, '(1 + 2)', $db->select(10)], "GREATEST(1, 1.5, (1 + 2), (SELECT 10))", 10, ]; @@ -1908,7 +1908,7 @@ public static function multiOperandFunctionBuilder(): iterable ]; yield 'Least with 4 operands' => [ Least::class, - static fn(Connectioninterface $db) => [1, 1.5, '(1 + 2)', $db->select(10)], + static fn(ConnectionInterface $db) => [1, 1.5, '(1 + 2)', $db->select(10)], "LEAST(1, 1.5, (1 + 2), (SELECT 10))", 1, ]; @@ -1931,7 +1931,7 @@ public static function multiOperandFunctionBuilder(): iterable ]; yield 'Longest with 3 operands' => [ Longest::class, - static fn(Connectioninterface $db) => [ + static fn(ConnectionInterface $db) => [ new Value('short'), $db->select(new Expression("'longest'")), new Param('string', DataType::STRING), @@ -1962,7 +1962,7 @@ public static function multiOperandFunctionBuilder(): iterable ]; yield 'Shortest with 3 operands' => [ Shortest::class, - static fn(Connectioninterface $db) => [ + static fn(ConnectionInterface $db) => [ new Value('short'), $db->select(new Expression("'longest'")), new Param('string', DataType::STRING),