Fix #20607: Add PHPStan/Psalm annotations for DB schemas

This commit is contained in:
Maksim Spirkov
2025-10-14 20:04:34 +03:00
committed by GitHub
parent d022321574
commit 9e45755a8e
9 changed files with 59 additions and 17 deletions

View File

@@ -57,6 +57,7 @@ Yii Framework 2 Change Log
- Bug #20605: Fix return value in `SerialColumn::renderDataCellContent()` (mspirkov)
- Bug #20604: Fix `@var` annotation for `yii\db\Command::$pdoStatement` (mspirkov)
- Bug #20600: Fix `@var` annotation for `yii\test\FileFixtureTrait::$dataFile` (mspirkov)
- Enh #20607: Add PHPStan/Psalm annotations for DB schemas (mspirkov)
- Bug #20608: Fix `@return` annotations for `yii\rest\Serializer` methods (mspirkov)
- Bug #20610: Fix `@var` annotation for `ActiveQueryTrait::$with` (mspirkov)
- Bug #20611: Fix `@return` annotations for `yii\i18n\GettextMoFile` methods (mspirkov)

View File

@@ -37,6 +37,8 @@ use yii\caching\TagDependency;
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Sergey Makinen <sergey@makinen.ru>
* @since 2.0
*
* @template T of ColumnSchema
*/
abstract class Schema extends BaseObject
{
@@ -87,6 +89,9 @@ abstract class Schema extends BaseObject
/**
* @var string|array column schema class or class config
* @since 2.0.11
*
* @phpstan-var class-string<T>|array{class?: class-string<T>, __class?: class-string<T>, ...}
* @psalm-var class-string<T>|array{class?: class-string<T>, __class?: class-string<T>, ...}
*/
public $columnSchemaClass = 'yii\db\ColumnSchema';
@@ -175,6 +180,9 @@ abstract class Schema extends BaseObject
* This method may be overridden by child classes to create a DBMS-specific column schema.
* @return ColumnSchema column schema instance.
* @throws InvalidConfigException if a column schema class cannot be created.
*
* @phpstan-return T
* @psalm-return T
*/
protected function createColumnSchema()
{

View File

@@ -9,6 +9,7 @@ namespace yii\db\cubrid;
use Yii;
use yii\base\NotSupportedException;
use yii\db\ColumnSchema;
use yii\db\Constraint;
use yii\db\ConstraintFinderInterface;
use yii\db\ConstraintFinderTrait;
@@ -18,14 +19,18 @@ use yii\db\IndexConstraint;
use yii\db\TableSchema;
use yii\db\Transaction;
use yii\helpers\ArrayHelper;
use yii\db\Schema as BaseSchema;
/**
* Schema is the class for retrieving metadata from a CUBRID database (version 9.3.x and higher).
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*
* @template T of ColumnSchema
* @extends BaseSchema<T>
*/
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
class Schema extends BaseSchema implements ConstraintFinderInterface
{
use ConstraintFinderTrait;
@@ -255,7 +260,10 @@ class Schema extends \yii\db\Schema implements ConstraintFinderInterface
/**
* Loads the column information into a [[ColumnSchema]] object.
* @param array $info column information
* @return \yii\db\ColumnSchema the column schema object
* @return ColumnSchema the column schema object
*
* @phpstan-return T
* @psalm-return T
*/
protected function loadColumnSchema($info)
{

View File

@@ -17,14 +17,18 @@ use yii\db\ForeignKeyConstraint;
use yii\db\IndexConstraint;
use yii\db\ViewFinderTrait;
use yii\helpers\ArrayHelper;
use yii\db\Schema as BaseSchema;
/**
* Schema is the class for retrieving metadata from MS SQL Server databases (version 2008 and above).
*
* @author Timur Ruziev <resurtm@gmail.com>
* @since 2.0
*
* @template T of ColumnSchema
* @extends BaseSchema<T>
*/
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
class Schema extends BaseSchema implements ConstraintFinderInterface
{
use ViewFinderTrait;
use ConstraintFinderTrait;
@@ -372,6 +376,9 @@ SQL;
* Loads the column information into a [[ColumnSchema]] object.
* @param array $info column information
* @return ColumnSchema the column schema object
*
* @phpstan-return T
* @psalm-return T
*/
protected function loadColumnSchema($info)
{

View File

@@ -20,14 +20,18 @@ use yii\db\ForeignKeyConstraint;
use yii\db\IndexConstraint;
use yii\db\TableSchema;
use yii\helpers\ArrayHelper;
use yii\db\Schema as BaseSchema;
/**
* Schema is the class for retrieving metadata from a MySQL database (version 4.1.x and 5.x).
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of ColumnSchema
* @extends BaseSchema<T>
*/
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
class Schema extends BaseSchema implements ConstraintFinderInterface
{
use ConstraintFinderTrait;
@@ -282,6 +286,9 @@ SQL;
* Loads the column information into a [[ColumnSchema]] object.
* @param array $info column information
* @return ColumnSchema the column schema object
*
* @phpstan-return T
* @psalm-return T
*/
protected function loadColumnSchema($info)
{

View File

@@ -21,6 +21,7 @@ use yii\db\ForeignKeyConstraint;
use yii\db\IndexConstraint;
use yii\db\TableSchema;
use yii\helpers\ArrayHelper;
use yii\db\Schema as BaseSchema;
/**
* Schema is the class for retrieving metadata from an Oracle database.
@@ -30,8 +31,11 @@ use yii\helpers\ArrayHelper;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of ColumnSchema
* @extends BaseSchema<T>
*/
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
class Schema extends BaseSchema implements ConstraintFinderInterface
{
use ConstraintFinderTrait;
@@ -398,6 +402,9 @@ SQL;
*
* @param array $column
* @return ColumnSchema
*
* @phpstan-return T
* @psalm-return T
*/
protected function createColumn($column)
{

View File

@@ -19,6 +19,7 @@ use yii\db\IndexConstraint;
use yii\db\TableSchema;
use yii\db\ViewFinderTrait;
use yii\helpers\ArrayHelper;
use yii\db\Schema as BaseSchema;
/**
* Schema is the class for retrieving metadata from a PostgreSQL database
@@ -26,8 +27,11 @@ use yii\helpers\ArrayHelper;
*
* @author Gevik Babakhani <gevikb@gmail.com>
* @since 2.0
*
* @template T of ColumnSchema
* @extends BaseSchema<T>
*/
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
class Schema extends BaseSchema implements ConstraintFinderInterface
{
use ViewFinderTrait;
use ConstraintFinderTrait;
@@ -589,6 +593,9 @@ SQL;
* Loads the column information into a [[ColumnSchema]] object.
* @param array $info column information
* @return ColumnSchema the column schema object
*
* @phpstan-return T
* @psalm-return T
*/
protected function loadColumnSchema($info)
{

View File

@@ -21,6 +21,7 @@ use yii\db\SqlToken;
use yii\db\TableSchema;
use yii\db\Transaction;
use yii\helpers\ArrayHelper;
use yii\db\Schema as BaseSchema;
/**
* Schema is the class for retrieving metadata from a SQLite (2/3) database.
@@ -30,8 +31,11 @@ use yii\helpers\ArrayHelper;
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*
* @template T of ColumnSchema
* @extends BaseSchema<T>
*/
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
class Schema extends BaseSchema implements ConstraintFinderInterface
{
use ConstraintFinderTrait;
@@ -306,6 +310,9 @@ class Schema extends \yii\db\Schema implements ConstraintFinderInterface
* Loads the column information into a [[ColumnSchema]] object.
* @param array $info column information
* @return ColumnSchema the column schema object
*
* @phpstan-return T
* @psalm-return T
*/
protected function loadColumnSchema($info)
{

View File

@@ -85,16 +85,6 @@ parameters:
count: 1
path: framework/db/mysql/JsonExpressionBuilder.php
-
message: "#^Access to an undefined property yii\\\\db\\\\ColumnSchema\\:\\:\\$isComputed\\.$#"
count: 1
path: framework/db/mssql/Schema.php
-
message: "#^Call to an undefined method yii\\\\db\\\\ColumnSchema\\:\\:defaultPhpTypecast\\(\\)\\.$#"
count: 1
path: framework/db/mssql/Schema.php
-
message: "#^Call to an undefined method yii\\\\db\\\\Schema\\:\\:getViewNames\\(\\)\\.$#"
count: 1