Skip to content

Commit 9e45755

Browse files
authored
Fix #20607: Add PHPStan/Psalm annotations for DB schemas
1 parent d022321 commit 9e45755

File tree

9 files changed

+59
-17
lines changed

9 files changed

+59
-17
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Yii Framework 2 Change Log
5757
- Bug #20605: Fix return value in `SerialColumn::renderDataCellContent()` (mspirkov)
5858
- Bug #20604: Fix `@var` annotation for `yii\db\Command::$pdoStatement` (mspirkov)
5959
- Bug #20600: Fix `@var` annotation for `yii\test\FileFixtureTrait::$dataFile` (mspirkov)
60+
- Enh #20607: Add PHPStan/Psalm annotations for DB schemas (mspirkov)
6061
- Bug #20608: Fix `@return` annotations for `yii\rest\Serializer` methods (mspirkov)
6162
- Bug #20610: Fix `@var` annotation for `ActiveQueryTrait::$with` (mspirkov)
6263
- Bug #20611: Fix `@return` annotations for `yii\i18n\GettextMoFile` methods (mspirkov)

framework/db/Schema.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
* @author Qiang Xue <qiang.xue@gmail.com>
3838
* @author Sergey Makinen <sergey@makinen.ru>
3939
* @since 2.0
40+
*
41+
* @template T of ColumnSchema
4042
*/
4143
abstract class Schema extends BaseObject
4244
{
@@ -87,6 +89,9 @@ abstract class Schema extends BaseObject
8789
/**
8890
* @var string|array column schema class or class config
8991
* @since 2.0.11
92+
*
93+
* @phpstan-var class-string<T>|array{class?: class-string<T>, __class?: class-string<T>, ...}
94+
* @psalm-var class-string<T>|array{class?: class-string<T>, __class?: class-string<T>, ...}
9095
*/
9196
public $columnSchemaClass = 'yii\db\ColumnSchema';
9297

@@ -175,6 +180,9 @@ abstract protected function loadTableSchema($name);
175180
* This method may be overridden by child classes to create a DBMS-specific column schema.
176181
* @return ColumnSchema column schema instance.
177182
* @throws InvalidConfigException if a column schema class cannot be created.
183+
*
184+
* @phpstan-return T
185+
* @psalm-return T
178186
*/
179187
protected function createColumnSchema()
180188
{

framework/db/cubrid/Schema.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Yii;
1111
use yii\base\NotSupportedException;
12+
use yii\db\ColumnSchema;
1213
use yii\db\Constraint;
1314
use yii\db\ConstraintFinderInterface;
1415
use yii\db\ConstraintFinderTrait;
@@ -18,14 +19,18 @@
1819
use yii\db\TableSchema;
1920
use yii\db\Transaction;
2021
use yii\helpers\ArrayHelper;
22+
use yii\db\Schema as BaseSchema;
2123

2224
/**
2325
* Schema is the class for retrieving metadata from a CUBRID database (version 9.3.x and higher).
2426
*
2527
* @author Carsten Brandt <mail@cebe.cc>
2628
* @since 2.0
29+
*
30+
* @template T of ColumnSchema
31+
* @extends BaseSchema<T>
2732
*/
28-
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
33+
class Schema extends BaseSchema implements ConstraintFinderInterface
2934
{
3035
use ConstraintFinderTrait;
3136

@@ -255,7 +260,10 @@ public function createQueryBuilder()
255260
/**
256261
* Loads the column information into a [[ColumnSchema]] object.
257262
* @param array $info column information
258-
* @return \yii\db\ColumnSchema the column schema object
263+
* @return ColumnSchema the column schema object
264+
*
265+
* @phpstan-return T
266+
* @psalm-return T
259267
*/
260268
protected function loadColumnSchema($info)
261269
{

framework/db/mssql/Schema.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
use yii\db\IndexConstraint;
1818
use yii\db\ViewFinderTrait;
1919
use yii\helpers\ArrayHelper;
20+
use yii\db\Schema as BaseSchema;
2021

2122
/**
2223
* Schema is the class for retrieving metadata from MS SQL Server databases (version 2008 and above).
2324
*
2425
* @author Timur Ruziev <resurtm@gmail.com>
2526
* @since 2.0
27+
*
28+
* @template T of ColumnSchema
29+
* @extends BaseSchema<T>
2630
*/
27-
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
31+
class Schema extends BaseSchema implements ConstraintFinderInterface
2832
{
2933
use ViewFinderTrait;
3034
use ConstraintFinderTrait;
@@ -372,6 +376,9 @@ protected function resolveTableNames($table, $name)
372376
* Loads the column information into a [[ColumnSchema]] object.
373377
* @param array $info column information
374378
* @return ColumnSchema the column schema object
379+
*
380+
* @phpstan-return T
381+
* @psalm-return T
375382
*/
376383
protected function loadColumnSchema($info)
377384
{

framework/db/mysql/Schema.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@
2020
use yii\db\IndexConstraint;
2121
use yii\db\TableSchema;
2222
use yii\helpers\ArrayHelper;
23+
use yii\db\Schema as BaseSchema;
2324

2425
/**
2526
* Schema is the class for retrieving metadata from a MySQL database (version 4.1.x and 5.x).
2627
*
2728
* @author Qiang Xue <qiang.xue@gmail.com>
2829
* @since 2.0
30+
*
31+
* @template T of ColumnSchema
32+
* @extends BaseSchema<T>
2933
*/
30-
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
34+
class Schema extends BaseSchema implements ConstraintFinderInterface
3135
{
3236
use ConstraintFinderTrait;
3337

@@ -282,6 +286,9 @@ protected function resolveTableNames($table, $name)
282286
* Loads the column information into a [[ColumnSchema]] object.
283287
* @param array $info column information
284288
* @return ColumnSchema the column schema object
289+
*
290+
* @phpstan-return T
291+
* @psalm-return T
285292
*/
286293
protected function loadColumnSchema($info)
287294
{

framework/db/oci/Schema.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use yii\db\IndexConstraint;
2222
use yii\db\TableSchema;
2323
use yii\helpers\ArrayHelper;
24+
use yii\db\Schema as BaseSchema;
2425

2526
/**
2627
* Schema is the class for retrieving metadata from an Oracle database.
@@ -30,8 +31,11 @@
3031
*
3132
* @author Qiang Xue <qiang.xue@gmail.com>
3233
* @since 2.0
34+
*
35+
* @template T of ColumnSchema
36+
* @extends BaseSchema<T>
3337
*/
34-
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
38+
class Schema extends BaseSchema implements ConstraintFinderInterface
3539
{
3640
use ConstraintFinderTrait;
3741

@@ -398,6 +402,9 @@ public function getLastInsertID($sequenceName = '')
398402
*
399403
* @param array $column
400404
* @return ColumnSchema
405+
*
406+
* @phpstan-return T
407+
* @psalm-return T
401408
*/
402409
protected function createColumn($column)
403410
{

framework/db/pgsql/Schema.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
use yii\db\TableSchema;
2020
use yii\db\ViewFinderTrait;
2121
use yii\helpers\ArrayHelper;
22+
use yii\db\Schema as BaseSchema;
2223

2324
/**
2425
* Schema is the class for retrieving metadata from a PostgreSQL database
2526
* (version 9.x and above).
2627
*
2728
* @author Gevik Babakhani <gevikb@gmail.com>
2829
* @since 2.0
30+
*
31+
* @template T of ColumnSchema
32+
* @extends BaseSchema<T>
2933
*/
30-
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
34+
class Schema extends BaseSchema implements ConstraintFinderInterface
3135
{
3236
use ViewFinderTrait;
3337
use ConstraintFinderTrait;
@@ -589,6 +593,9 @@ protected function findColumns($table)
589593
* Loads the column information into a [[ColumnSchema]] object.
590594
* @param array $info column information
591595
* @return ColumnSchema the column schema object
596+
*
597+
* @phpstan-return T
598+
* @psalm-return T
592599
*/
593600
protected function loadColumnSchema($info)
594601
{

framework/db/sqlite/Schema.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use yii\db\TableSchema;
2222
use yii\db\Transaction;
2323
use yii\helpers\ArrayHelper;
24+
use yii\db\Schema as BaseSchema;
2425

2526
/**
2627
* Schema is the class for retrieving metadata from a SQLite (2/3) database.
@@ -30,8 +31,11 @@
3031
*
3132
* @author Qiang Xue <qiang.xue@gmail.com>
3233
* @since 2.0
34+
*
35+
* @template T of ColumnSchema
36+
* @extends BaseSchema<T>
3337
*/
34-
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
38+
class Schema extends BaseSchema implements ConstraintFinderInterface
3539
{
3640
use ConstraintFinderTrait;
3741

@@ -306,6 +310,9 @@ public function findUniqueIndexes($table)
306310
* Loads the column information into a [[ColumnSchema]] object.
307311
* @param array $info column information
308312
* @return ColumnSchema the column schema object
313+
*
314+
* @phpstan-return T
315+
* @psalm-return T
309316
*/
310317
protected function loadColumnSchema($info)
311318
{

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,6 @@ parameters:
8585
count: 1
8686
path: framework/db/mysql/JsonExpressionBuilder.php
8787

88-
-
89-
message: "#^Access to an undefined property yii\\\\db\\\\ColumnSchema\\:\\:\\$isComputed\\.$#"
90-
count: 1
91-
path: framework/db/mssql/Schema.php
92-
93-
-
94-
message: "#^Call to an undefined method yii\\\\db\\\\ColumnSchema\\:\\:defaultPhpTypecast\\(\\)\\.$#"
95-
count: 1
96-
path: framework/db/mssql/Schema.php
97-
9888
-
9989
message: "#^Call to an undefined method yii\\\\db\\\\Schema\\:\\:getViewNames\\(\\)\\.$#"
10090
count: 1

0 commit comments

Comments
 (0)