From 337344e3f594cd287fb60ed948fe8ba01d5c917f Mon Sep 17 00:00:00 2001 From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com> Date: Tue, 7 Mar 2023 19:55:21 -0300 Subject: [PATCH] Fix phpdoc `Schema` classes. (#586) --- src/Schema/AbstractColumnSchema.php | 19 ++-- src/Schema/AbstractColumnSchemaBuilder.php | 11 +- src/Schema/AbstractSchema.php | 44 ++++---- src/Schema/AbstractTableSchema.php | 2 +- src/Schema/ColumnSchemaBuilderInterface.php | 19 ++-- src/Schema/ColumnSchemaInterface.php | 115 +++++++++++--------- src/Schema/Quoter.php | 20 ++-- src/Schema/QuoterInterface.php | 64 ++++++----- src/Schema/SchemaInterface.php | 28 ++--- src/Schema/TableSchemaInterface.php | 41 ++++--- 10 files changed, 198 insertions(+), 165 deletions(-) diff --git a/src/Schema/AbstractColumnSchema.php b/src/Schema/AbstractColumnSchema.php index 20ff4107f..507ab6762 100644 --- a/src/Schema/AbstractColumnSchema.php +++ b/src/Schema/AbstractColumnSchema.php @@ -18,11 +18,14 @@ use function is_resource; /** - * The ColumnSchema class represents the metadata of a column in a database table. It provides information about the - * column's name, type, size, precision, and other details. + * Represents the metadata of a column in a database table. * - * The ColumnSchema class is used to store and retrieve metadata about a column in a database table. It is typically - * used in conjunction with the TableSchema class, which represents the metadata of a database table as a whole. + * It provides information about the column's name, type, size, precision, and other details. + * + * The ColumnSchema class is used to store and retrieve metadata about a column in a database table. + * + * It's typically used in conjunction with the TableSchema class, which represents the metadata of a database table as a + * whole. * * Here is an example of how the ColumnSchema class might be used: * @@ -87,8 +90,8 @@ public function dbType(string $value): void public function dbTypecast(mixed $value): mixed { /** - * the default implementation does the same as casting for PHP, but it should be possible to override this with - * annotation of explicit PDO type. + * The default implementation does the same as casting for PHP, but it should be possible to override this with + * annotation of an explicit PDO type. */ return $this->typecast($value); } @@ -236,7 +239,7 @@ public function unsigned(bool $value): void /** * Converts the input value according to {@see phpType} after retrieval from the database. * - * If the value is null or an {@see Expression}, it will not be converted. + * If the value is null or an {@see Expression}, it won't be converted. * * @param mixed $value The value to be converted. * @@ -298,7 +301,7 @@ protected function typecast(mixed $value): mixed return (int) $value; case SchemaInterface::PHP_TYPE_BOOLEAN: /** - * treating a 0 bit value as false too + * Treating a 0-bit value as false too. * * @link https://github.com/yiisoft/yii2/issues/9006 */ diff --git a/src/Schema/AbstractColumnSchemaBuilder.php b/src/Schema/AbstractColumnSchemaBuilder.php index 6f6add689..c92d7ad3f 100644 --- a/src/Schema/AbstractColumnSchemaBuilder.php +++ b/src/Schema/AbstractColumnSchemaBuilder.php @@ -12,8 +12,7 @@ use function strtr; /** - * The AbstractColumnSchemaBuilder class is a utility class that provides a convenient way to create column schemas for - * use with Schema class @see Schema. + * Is a utility class that provides a convenient way to create column schemas for {@see AbstractSchema}. * * It provides methods for specifying the properties of a column, such as its type, size, default value, and whether it * is nullable or not. It also provides a method for creating a column schema based on the specified properties. @@ -24,15 +23,15 @@ * $column = (new ColumnSchemaBuilder(SchemaInterface::TYPE_INTEGER))->notNull()->defaultValue(0); * ``` * - * The AbstractColumnSchemaBuilder class provides a fluent interface, which means that the methods can be chained - * together to create a column schema with multiple properties in a single line of code. + * Provides a fluent interface, which means that the methods can be chained together to create a column schema with + * many properties in a single line of code. */ abstract class AbstractColumnSchemaBuilder implements ColumnSchemaBuilderInterface { /** * Internally used constants representing categories that abstract column types fall under. * - * {@see $categoryMap} for mappings of abstract column types to category. + * {@see $categoryMap} For mappings of abstract column types to category. */ public const CATEGORY_PK = 'pk'; public const CATEGORY_STRING = 'string'; @@ -126,8 +125,6 @@ public function comment(string|null $comment): static /** * Marks column as unsigned. - * - * @return static The column schema builder instance itself. */ public function unsigned(): static { diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index 255a112f3..9c069b089 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -23,10 +23,10 @@ use function str_replace; /** - * The AbstractSchema class provides a set of methods for working with database schemas such as creating, modifying, - * and inspecting tables, columns, and other database objects. + * Provides a set of methods for working with database schemas such as creating, modifying, and inspecting tables, + * columns, and other database objects. * - * It is a very powerful and flexible tool that allows you to perform a wide range of database operations in a + * It's a powerful and flexible tool that allows you to perform a wide range of database operations in a * database-agnostic way. */ abstract class AbstractSchema implements SchemaInterface @@ -123,7 +123,7 @@ abstract protected function loadTableUniques(string $tableName): array; * * @param string $name The table name. * - * @return TableSchemaInterface|null DBMS-dependent table metadata, `null` if the table does not exist. + * @return TableSchemaInterface|null DBMS-dependent table metadata, `null` if the table doesn't exist. */ abstract protected function loadTableSchema(string $name): TableSchemaInterface|null; @@ -213,7 +213,7 @@ public function getSchemaIndexes(string $schema = '', bool $refresh = false): ar } /** - * @throws NotSupportedException If this method is not supported by the underlying DBMS. + * @throws NotSupportedException If this method isn't supported by the underlying DBMS. * * @return array The schema names in the database, except system schemas. */ @@ -309,7 +309,7 @@ public function getTableIndexes(string $name, bool $refresh = false): array } /** - * @throws NotSupportedException If this method is not supported by the underlying DBMS. + * @throws NotSupportedException If this method isn't supported by the underlying DBMS. * * @return array The table names in the database. */ @@ -341,7 +341,7 @@ public function getTablePrimaryKey(string $name, bool $refresh = false): Constra * @throws InvalidCallException * @throws \Yiisoft\Db\Exception\InvalidArgumentException * - * @return TableSchemaInterface|null The table schema information. Null if the named table does not exist. + * @return TableSchemaInterface|null The table schema information. Null if the named table doesn't exist. */ public function getTableSchema(string $name, bool $refresh = false): TableSchemaInterface|null { @@ -425,12 +425,12 @@ public function schemaCacheEnable(bool $value): void /** * Returns all schema names in the database, including the default one but not system schemas. * - * This method should be overridden by child classes in order to support this feature because the default + * This method should be overridden by child classes to support this feature because the default * implementation simply throws an exception. * - * @throws NotSupportedException If this method is not supported by the DBMS. + * @throws NotSupportedException If the DBMS doesn't support this method. * - * @return array All schema names in the database, except system schemas. + * @return array All schemas name in the database, except system schemas. */ protected function findSchemaNames(): array { @@ -440,14 +440,14 @@ protected function findSchemaNames(): array /** * Returns all table names in the database. * - * This method should be overridden by child classes in order to support this feature because the default + * This method should be overridden by child classes to support this feature because the default * implementation simply throws an exception. * * @param string $schema The schema of the tables. Defaults to empty string, meaning the current or default schema. * - * @throws NotSupportedException If this method is not supported by the DBMS. + * @throws NotSupportedException If the DBMS doesn't support this method. * - * @return array All table names in the database. The names have NO schema name prefix. + * @return array All tables name in the database. The names have NO schema name prefix. */ protected function findTableNames(string $schema): array { @@ -455,7 +455,7 @@ protected function findTableNames(string $schema): array } /** - * Extracts the PHP type from abstract DB type. + * Extracts the PHP type from an abstract DB type. * * @param ColumnSchemaInterface $column The column schema information. * @@ -537,9 +537,10 @@ protected function getSchemaMetadata(string $schema, string $type, bool $refresh /** * Returns the metadata of the given type for the given table. * - * @param string $name The table name. The table name may contain schema name if any. Do not quote the table name. + * @param string $name The table name. The table name may contain a schema name if any. + * Don't quote the table name. * @param string $type The metadata type. - * @param bool $refresh whether to reload the table metadata even if it is found in the cache. + * @param bool $refresh whether to reload the table metadata even if it's found in the cache. * * @throws InvalidCallException * @throws InvalidArgumentException @@ -607,10 +608,10 @@ protected function getTableTypeMetadata( } /** - * Changes row's array key case to lower. + * Change row's array key case to lower. * - * @param array $row Thew row's array or an array of row's arrays. - * @param bool $multiple Whether multiple rows or a single row passed. + * @param array $row Thew row's array or an array of row arrays. + * @param bool $multiple Whether many rows or a single row passed. * * @return array The normalized row or rows. */ @@ -628,7 +629,7 @@ protected function normalizeRowKeyCase(array $row, bool $multiple): array * * @param string $name The table name. * - * @throws NotSupportedException If this method is not supported by the DBMS. + * @throws NotSupportedException If the DBMS doesn't support this method. * * @return TableSchemaInterface The with resolved table, schema, etc. names. * @@ -715,7 +716,8 @@ private function saveTableMetadataToCache(string $rawName): void /** * Find the view names for the database. * - * @param string $schema the schema of the views. Defaults to empty string, meaning the current or default schema. + * @param string $schema The schema of the views. + * Defaults to empty string, meaning the current or default schema. * * @return array The names of all views in the database. */ diff --git a/src/Schema/AbstractTableSchema.php b/src/Schema/AbstractTableSchema.php index 116309f37..904243a93 100644 --- a/src/Schema/AbstractTableSchema.php +++ b/src/Schema/AbstractTableSchema.php @@ -9,7 +9,7 @@ use function array_keys; /** - * TableSchema represents the metadata of a database table. + * Represents the metadata of a database table. */ abstract class AbstractTableSchema implements TableSchemaInterface { diff --git a/src/Schema/ColumnSchemaBuilderInterface.php b/src/Schema/ColumnSchemaBuilderInterface.php index b0d33bbad..6773b4b0a 100644 --- a/src/Schema/ColumnSchemaBuilderInterface.php +++ b/src/Schema/ColumnSchemaBuilderInterface.php @@ -5,16 +5,15 @@ namespace Yiisoft\Db\Schema; /** - * The ColumnSchemaBuilderInterface class is an interface that defines the methods that must be implemented by classes - * that build the schema of a database column. It provides methods for setting the column name, type, length, precision, - * scale, default value, and other properties of the column, as well as methods for adding constraints, such as primary - * key, unique, and not null. Classes that implement this interface are used to create and modify the schema of a - * database table in a database-agnostic way. + * This interface defines the methods that must be implemented by classes that build the schema of a database column. + * + * It provides methods for setting the column name, type, length, precision, scale, default value, and other properties + * of the column, as well as methods for adding constraints, such as a primary key, unique, and not null. */ interface ColumnSchemaBuilderInterface { /** - * Specify additional SQL to be appended to column definition. + * Specify more SQL to be appended to column definition. * * Position modifiers will be appended after column definition in databases that support them. * @@ -30,7 +29,7 @@ public function append(string $sql): self; public function setFormat(string $format): void; /** - * Builds the full string for the column's schema including type, length, default value, not null and other SQL + * Builds the full string for the column's schema including type, length, default value, not null and another SQL * fragment. * * @return string The SQL fragment that will be used for creating the column. @@ -100,7 +99,7 @@ public function getDefault(): mixed; /** * @return array|int|string|null The column size or precision definition. This is what goes into the parenthesis - * after the column type. This can be either a string, an integer or an array. If it is an array, the array values + * after the column type. This can be either a string, an integer or an array. If it's an array, the array values * will be joined into a string separated by comma. */ public function getLength(): array|int|string|null; @@ -111,8 +110,8 @@ public function getLength(): array|int|string|null; public function getType(): string|null; /** - * @return bool|null Whether the column is or not nullable. If this is `true`, a `NOT NULL` constraint will be - * added. If this is `false`, a `NULL` constraint will be added. + * @return bool|null Whether the column is or not nullable. If this is `true`, a `NOT NULL` constraint will be added. + * If this is `false`, a `NULL` constraint will be added. */ public function isNotNull(): bool|null; diff --git a/src/Schema/ColumnSchemaInterface.php b/src/Schema/ColumnSchemaInterface.php index 06b6f12c0..08eae957a 100644 --- a/src/Schema/ColumnSchemaInterface.php +++ b/src/Schema/ColumnSchemaInterface.php @@ -5,8 +5,8 @@ namespace Yiisoft\Db\Schema; /** - * The ColumnSchemaInterface class is an interface that defines a set of methods that must be implemented by a class - * that represents the column schema of a database table column. + * This interface defines a set of methods that must be implemented by a class that represents the column schema of a + * database table column. */ interface ColumnSchemaInterface { @@ -14,8 +14,8 @@ interface ColumnSchemaInterface * The allowNull can be set to either `true` or `false`, depending on whether null values should be allowed in the * ColumnSchema class. * - * By default, the allowNull is set to `false`, so if it is not specified when defining a ColumnSchema class, - * null values will not be allowed in the ColumnSchema class. + * By default, the allowNull is set to `false`, so if it isn't specified when defining a ColumnSchema class, + * null values won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -26,13 +26,13 @@ interface ColumnSchemaInterface public function allowNull(bool $value): void; /** - * The autoIncrement is a column that is assigned a unique value automatically by the database management system + * The autoIncrement is a column that's assigned a unique value automatically by the database management system * (DBMS) whenever a new row is inserted into the table. This is useful for generating unique IDs for rows in the * table, such as customer or employee numbers. The autoIncrement attribute can be specified for `INTEGER` or * `BIGINT` data types. * - * By default, the autoIncrement is set to `false`, so if it is not specified when defining a ColumnSchema class, - * the autoIncrement will not be allowed in the ColumnSchema class. + * By default, the autoIncrement is set to `false`, so if it isn't specified when defining a ColumnSchema class, + * the autoIncrement won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -43,11 +43,12 @@ public function allowNull(bool $value): void; public function autoIncrement(bool $value): void; /** - * The comment refers to a string of text that can be added to a column in a database table. The comment can provide - * additional information about the purpose or usage of the column. + * The comment refers to a string of text that can be added to a column in a database table. * - * By default, the comment is set to `null`, so if it is not specified when defining a ColumnSchema class, the - * comment will not be allowed in the ColumnSchema class. + * The comment can give more information about the purpose or usage of the column. + * + * By default, the comment is set to `null`, so if it isn't specified when defining a ColumnSchema class, the + * comment won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -61,8 +62,8 @@ public function comment(string|null $value): void; * A computed column is a virtual column that computes its values from an expression. We can use a constant value, * function, value derived from other columns, non-computed column name, or their combinations. * - * By default, the computed is set to `false`, so if it is not specified when defining a ColumnSchema class, the - * computed will not be allowed in the ColumnSchema class. + * By default, the computed is set to `false`, so if it isn't specified when defining a ColumnSchema class, the + * computed won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -99,24 +100,24 @@ public function dbType(string $value): void; /** * The dbTypecast is used to convert a value from its PHP representation to a database-specific representation. - * It is typically used when preparing a SQL statement for execution, to ensure that the values being bound to + * It's typically used when preparing an SQL statement for execution, to ensure that the values being bound to * placeholders in the statement are in a format that the database can understand. * - * The dbTypecast method is typically called automatically by the yiisoft/db library when preparing a SQL + * The dbTypecast method is typically called automatically by the yiisoft/db library when preparing an SQL * statement for execution, so you don't usually need to call it directly in your code. However, it can be useful * to understand how it works if you need to customize the way that values are converted for use in a SQL statement. * - * If the value is null or an {@see Expression}, it will not be converted. + * If the value is null or an {@see Expression}, it won't be converted. */ public function dbTypecast(mixed $value): mixed; /** - * The default value is a value that is automatically assigned to a column when a new row is inserted into the + * The default value is a value that's automatically assigned to a column when a new row is inserted into the * database table. The default value can be a constant value, function, value derived from other columns, * non-computed column name, or their combinations. * - * By default, value is set to `null`, so if it is not specified when defining a ColumnSchema class, the default - * value will not be allowed in the ColumnSchema class. + * By default, value is set to `null`, so if it isn't specified when defining a ColumnSchema class, the default + * value won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -127,10 +128,12 @@ public function dbTypecast(mixed $value): mixed; public function defaultValue(mixed $value): void; /** - * The enumValues is a list of possible values for the column. It is used only for `ENUM` columns. + * The enumValues is a list of possible values for the column. + * + * It's used only for `ENUM` columns. * - * By default, the enumValues is set to `null`, so if it is not specified when defining a ColumnSchema class, the - * enumValues will not be allowed in the ColumnSchema class. + * By default, the enumValues are set to `null`, so if it isn't specified when defining a ColumnSchema class, the + * enumValues won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -141,12 +144,14 @@ public function defaultValue(mixed $value): void; public function enumValues(array|null $value): void; /** - * The extra column schema refers to a string attribute that can be used to specify additional SQL to be appended to - * the generated SQL for a column. This can be useful for adding custom constraints or other SQL statements that are - * not supported by the column schema itself. + * The extra column schema refers to a string attribute that can be used to specify more SQL to be appended to the + * generated SQL for a column. + * + * This can be useful for adding custom constraints or other SQL statements that aren't supported by the column + * schema itself. * - * By default, the extra is set to `null`, so if it is not specified when defining a ColumnSchema class, the extra - * will not be allowed in the ColumnSchema class. + * By default, the extra is set to `null`, so if it isn't specified when defining a ColumnSchema class, the extra + * won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -181,7 +186,7 @@ public function getDbType(): string; public function getDefaultValue(): mixed; /** - * @return array|null The enum values of the column. `null` if no enum values has been defined. + * @return array|null The enum values of the column. `null` if no enum values have been defined. * By default, it returns `null`. * * @see enumValues() @@ -252,8 +257,9 @@ public function getType(): string; public function isAllowNull(): bool; /** - * Whether this column is auto-incremental. This is only meaningful when {@see type} is `smallint`, `integer` - * or `bigint`. + * Whether this column is auto incremental. + * + * This is only meaningful when {@see type} is `smallint`, `integer` or `bigint`. * * @see autoIncrement() */ @@ -282,10 +288,13 @@ public function isPrimaryKey(): bool; public function isUnsigned(): bool; /** - * Represents the name of the column in the database. It is used to generate the SQL statement. + * Represents the name of the column in the database. * - * For default name is empty string. Db ColumnSchema class will generate name automatically based on the column - * name. + * It's used to generate the SQL statement. + * + * For default name is an empty string. + * + * The db ColumnSchema class will generate a name automatically based on the column name. * * ```php * $columns = [ @@ -296,10 +305,10 @@ public function isUnsigned(): bool; public function name(string $value): void; /** - * The phpType is used to return the PHP data type that is most appropriate for representing the data stored in the + * The phpType is used to return the PHP data type that's most appropriate for representing the data stored in the * column. This is determined based on the data type of the column as defined in the database schema. For example, * if the column is defined as a varchar or text data type, the phpType() method may return string. If the column - * is defined as an int or tinyint, the phpType() method may return integer. + * is defined as an int or tinyint, the phpType() method may return an integer. * * By default, the phpType is set to `null`. Db ColumnSchema class will generate phpType automatically based on the * column type. @@ -315,7 +324,7 @@ public function phpType(string|null $value): void; /** * Converts the input value according to {@see phpType} after retrieval from the database. * - * If the value is null or an {@see Expression}, it will not be converted. + * If the value is null or an {@see Expression}, it won't be converted. */ public function phpTypecast(mixed $value): mixed; @@ -323,8 +332,8 @@ public function phpTypecast(mixed $value): mixed; * The precision is the total number of digits that are used to represent the value. This is only meaningful when * {@see type} is `decimal`. * - * By default, the precision is set to `null`, so if it is not specified when defining a ColumnSchema class, the - * precision will not be allowed in the ColumnSchema class. + * By default, the precision is set to `null`, so if it isn't specified when defining a ColumnSchema class, the + * precision won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -338,8 +347,8 @@ public function precision(int|null $value): void; * ColumnSchema class is used to specify which column or columns should be used as the primary key for a particular * table. * - * By default, the primaryKey is set to `false`, so if it is not specified when defining a ColumnSchema class, the - * primaryKey will not be allowed in the ColumnSchema class. + * By default, the primaryKey is set to `false`, so if it isn't specified when defining a ColumnSchema class, the + * primaryKey won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -353,8 +362,8 @@ public function primaryKey(bool $value): void; * The scale is the number of digits to the right of the decimal point and is only meaningful when {@see type} is * `decimal`. * - * By default, the scale is set to `null`, so if it is not specified when defining a ColumnSchema class, the scale - * will not be allowed in the ColumnSchema class. + * By default, the scale is set to `null`, so if it isn't specified when defining a ColumnSchema class, the scale + * won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -369,8 +378,8 @@ public function scale(int|null $value): void; * typically used for character or numeric data types, such as VARCHAR or INT, to specify the maximum length or * precision of the data that can be stored in the column. * - * By default, the size is set to `null`, so if it is not specified when defining a ColumnSchema class, the size - * will not be allowed in the ColumnSchema class. + * By default, the size is set to `null`, so if it isn't specified when defining a ColumnSchema class, the size + * won't be allowed in the ColumnSchema class. * * ```php * $columns = [ @@ -381,12 +390,14 @@ public function scale(int|null $value): void; public function size(int|null $value): void; /** - * The type of the ColumnSchema class that is used to set the data type of column in a database table. The data - * type of column specifies the kind of values that can be stored in that column, such as integers, strings, - * dates, or floating point numbers. + * The type of the ColumnSchema class that's used to set the data type of column in a database table. + * + * The data type of column specifies the kind of values that can be stored in that column, such as integers, + * strings, dates, or floating point numbers. + * + * By default, the type is set to empty strings. * - * By default, the type is set to empty string. Db ColumnSchema class will generate setType automatically based - * on the column type. + * The db ColumnSchema class will generate setType automatically based on the column type. * * ```php * $columns = [ @@ -397,11 +408,11 @@ public function type(string $value): void; /** * The unsigned is used to specify that a column in a database table should be an unsigned integer. An unsigned - * integer is a data type that can only represent positive whole numbers, and cannot represent negative numbers + * integer is a data type that can only represent positive whole numbers, and can't represent negative numbers * or decimal values. * - * By default, the unsigned is set to `false`, so if it is not specified when defining a ColumnSchema class, the - * unsigned will not be allowed in the ColumnSchema class. + * By default, the unsigned is set to `false`, so if it isn't specified, when defining a ColumnSchema class, the + * unsigned won't be allowed in the ColumnSchema class. * * ```php * $columns = [ diff --git a/src/Schema/Quoter.php b/src/Schema/Quoter.php index 2de4b36d1..93300cc67 100644 --- a/src/Schema/Quoter.php +++ b/src/Schema/Quoter.php @@ -18,12 +18,16 @@ use function substr; /** - * The Quoter is a class that is used to quote table and column names for use in SQL statements. It provides a set of - * methods for quoting different types of names, such as table names, column names, and schema names. + * The Quoter is a class that's used to quote table and column names for use in SQL statements. * - * The Quoter class is used by @see \Yiisoft\Db\QueryBuilder\QueryBuilder to quote names that need to be quoted. It is - * also used by @see \Yiisoft\Db\Command\Command to quote names in SQL statements before passing them to database - * servers. + * 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 that need to be + * quoted. + * + * It's also used by {@see \Yiisoft\Db\Command\AbstractCommand} to quote names in SQL statements before passing them to + * database servers. */ class Quoter implements QuoterInterface { @@ -216,10 +220,8 @@ public function unquoteSimpleTableName(string $name): string } /** - * @param string[] $parts - * @param bool $withColumn - * - * @return string[] + * @psalm-param string[] $parts Parts of table name + * @psalm-return string[] */ protected function unquoteParts(array $parts, bool $withColumn): array { diff --git a/src/Schema/QuoterInterface.php b/src/Schema/QuoterInterface.php index 351a7091b..d430b0b9b 100644 --- a/src/Schema/QuoterInterface.php +++ b/src/Schema/QuoterInterface.php @@ -8,21 +8,21 @@ use Yiisoft\Db\Expression\ExpressionInterface; /** - * The QuoterInterface class is an interface that provides a set of methods that can be used to quote table and column - * names, values, and other SQL expressions independently of the database. + * This interface provides a set of methods that can be used to quote table and column names, values, and other SQL + * expressions independently of the database. */ interface QuoterInterface { /** - * Clean up table names and aliases. + * Clean-up table names and aliases. * - * Both aliases and names are enclosed into {{ and }}. + * Both aliases and names are enclosed into `{{ and }}`. * - * @param array $tableNames non-empty array + * @param array $tableNames Non-empty array. * * @throws InvalidArgumentException * - * @psalm-return array table names indexed by aliases + * @psalm-return array */ public function cleanUpTableNames(array $tableNames): array; @@ -30,14 +30,14 @@ public function cleanUpTableNames(array $tableNames): array; * Splits full table name into parts. * * @param string $name The full name of the table. - * @param bool $withColumn For cases when full name contain as last prat name of column. + * @param bool $withColumn For cases when full name has as last prat name of column. * * @return string[] The table name parts. */ public function getTableNameParts(string $name, bool $withColumn = false): array; /** - * Ensures name is wrapped with {{ and }}. + * Ensures name is wrapped with `{{ and }}`. * * @param string $name The name to be quoted. * @@ -46,7 +46,7 @@ public function getTableNameParts(string $name, bool $withColumn = false): array public function ensureNameQuoted(string $name): string; /** - * Ensures name of column is wrapped with [[ and ]]. + * Ensures name of the column is wrapped with `[[ and ]]`. * * @param string $name The name to be quoted. * @@ -57,12 +57,12 @@ public function ensureColumnName(string $name): string; /** * Quotes a column name for use in a query. * - * If the column name contains prefix, the prefix will also be properly quoted. If the column name is already quoted - * or contains '(', '[[' or '{{', then this method will do nothing. + * If the column name has a prefix, the prefix will also be quoted. + * If the column name is already quoted or contains '(', '[[' or '{{', then this method will do nothing. * * @param string $name The column name to be quoted. * - * @return string The properly quoted column name. + * @return string The quoted column name. * * @see quoteSimpleColumnName() */ @@ -76,7 +76,7 @@ public function quoteColumnName(string $name): string; * * @param string $name The column name to be quoted. * - * @return string The properly quoted column name. + * @return string The quoted column name. */ public function quoteSimpleColumnName(string $name): string; @@ -88,16 +88,20 @@ public function quoteSimpleColumnName(string $name): string; * * @param string $name The table name to be quoted. * - * @return string The properly quoted table name. + * @return string The quoted table name. */ public function quoteSimpleTableName(string $name): string; /** - * Processes a SQL statement by quoting table and column names that are enclosed within double brackets. + * Processes an SQL statement by quoting table and column names that are inside within double brackets. * - * Tokens enclosed within double curly brackets are treated as table names, while tokens enclosed within double - * square brackets are column names. They will be quoted accordingly. Also, the percentage character "%" at the - * beginning or ending of a table name will be replaced with {@see tablePrefix}. + * Tokens inside within double curly brackets are treated as table names, while tokens inside within double square + * brackets are column names. + * + * They will be quoted so. + * + * Also, the percentage character "%" at the beginning or ending of a table name will be replaced with + * {@see \Yiisoft\Db\Connection\ConnectionInterface::setTablePrefix()}. * * @param string $sql The SQL statement to be quoted. * @@ -108,12 +112,13 @@ public function quoteSql(string $sql): string; /** * Quotes a table name for use in a query. * - * If the table name contains schema prefix, the prefix will also be properly quoted. If the table name is already - * quoted or contains '(' or '{{', then this method will do nothing. + * If the table name has a schema prefix, the prefix will also be quoted. + * + * If the table name is already quoted or has '(' or '{{', then this method will do nothing. * * @param string $name The table name to be quoted. * - * @return string The properly quoted table name. + * @return string The quoted table name. * * @see quoteSimpleTableName() */ @@ -122,20 +127,22 @@ public function quoteTableName(string $name): string; /** * Quotes a string value for use in a query. * - * Note that if the parameter is not a string, it will be returned without change. - * Attention: The usage of this method is not safe. Use prepared statements. + * Note: That if the parameter isn't a string, it will be returned without change. + * Attention: The usage of this method isn't safe. + * Use prepared statements. * * @param mixed $value The value to be quoted. * - * @return mixed The properly quoted value. + * @return mixed The quoted value. */ public function quoteValue(mixed $value): mixed; /** * Unquotes a simple column name. * - * A simple column name should contain the column name only without any prefix. If the column name is not quoted or - * is the asterisk character '*', this method will do nothing. + * A simple column name should contain the column name only without any prefix. + * + * If the column name isn't quoted or is the asterisk character '*', this method will do nothing. * * @param string $name The column name to be unquoted. * @@ -146,8 +153,9 @@ public function unquoteSimpleColumnName(string $name): string; /** * Unquotes a simple table name. * - * A simple table name should contain the table name only without any schema prefix. If the table name is not - * quoted, this method will do nothing. + * A simple table name should contain the table name only without any schema prefix. + * + * If the table name isn't quoted, this method will do nothing. * * @param string $name The table name to be unquoted. * diff --git a/src/Schema/SchemaInterface.php b/src/Schema/SchemaInterface.php index 255b90d85..9ccb6d42e 100644 --- a/src/Schema/SchemaInterface.php +++ b/src/Schema/SchemaInterface.php @@ -11,9 +11,10 @@ use Yiisoft\Db\Exception\NotSupportedException; /** - * The SchemaInterface class that represents the schema for a database table. It provides a set of methods for working - * with the schema of a database table, such as accessing the columns, indexes, and constraints of a table, as well as - * methods for creating, dropping, and altering tables. + * Represents the schema for a database table. + * + * It provides a set of methods for working with the schema of a database table, such as accessing the columns, + * indexes, and constraints of a table, as well as methods for creating, dropping, and altering tables. */ interface SchemaInterface extends ConstraintSchemaInterface { @@ -108,11 +109,11 @@ public function getRawTableName(string $name): string; * Returns all schema names in the database, except system schemas. * * @param bool $refresh Whether to fetch the latest available schema names. If this is false, schema names fetched - * previously (if available) will be returned. + * before (if available) will be returned. * * @throws NotSupportedException * - * @return array All schema names in the database, except system schemas. + * @return array All schemas name in the database, except system schemas. */ public function getSchemaNames(bool $refresh = false): array; @@ -123,11 +124,11 @@ public function getSchemaNames(bool $refresh = false): array; * name. * If not empty, the returned table names will be prefixed with the schema name. * @param bool $refresh Whether to fetch the latest available table names. If this is false, table names fetched - * previously (if available) will be returned. + * before (if available) will be returned. * * @throws NotSupportedException * - * @return array All table names in the database. + * @return array All tables name in the database. */ public function getTableNames(string $schema = '', bool $refresh = false): array; @@ -176,10 +177,11 @@ public function findUniqueIndexes(TableSchemaInterface $table): array; /** * Obtains the metadata for the named table. * - * @param string $name Table name. The table name may contain schema name if any. Do not quote the table name. - * @param bool $refresh Whether to reload the table schema even if it is found in the cache. + * @param string $name Table name. The table name may contain a schema name if any. + * Don't quote the table name. + * @param bool $refresh Whether to reload the table schema even if it's found in the cache. * - * @return TableSchemaInterface|null Table metadata. `null` if the named table does not exist. + * @return TableSchemaInterface|null Table metadata. `null` if the named table doesn't exist. */ public function getTableSchema(string $name, bool $refresh = false): TableSchemaInterface|null; @@ -199,11 +201,11 @@ public function getTableSchema(string $name, bool $refresh = false): TableSchema public function getTableSchemas(string $schema = '', bool $refresh = false): array; /** - * Returns a value indicating whether a SQL statement is for read purpose. + * Returns a value indicating whether an SQL statement is for read purpose. * * @param string $sql The SQL statement. * - * @return bool Whether a SQL statement is for read purpose. + * @return bool Whether an SQL statement is for read purpose. */ public function isReadQuery(string $sql): bool; @@ -238,7 +240,7 @@ public function schemaCacheEnable(bool $value): void; * @param string $schema The schema of the views. Defaults to empty string, meaning the current or default schema * name. If not empty, the returned view names will be prefixed with the schema name. * @param bool $refresh Whether to fetch the latest available view names. If this is false, view names fetched - * previously (if available) will be returned. + * before (if available) will be returned. * * @return array All view names in the database. */ diff --git a/src/Schema/TableSchemaInterface.php b/src/Schema/TableSchemaInterface.php index df425bdef..e721a86b6 100644 --- a/src/Schema/TableSchemaInterface.php +++ b/src/Schema/TableSchemaInterface.php @@ -7,20 +7,22 @@ use Yiisoft\Db\Exception\NotSupportedException; /** - * TableSchemaInterface represents the metadata of a database table. It defines a set of methods to retrieve the table - * name, schema name, column names, primary key, foreign keys, etc. The information is obtained from the database schema - * and may vary according to the DBMS type. + * Represents the metadata of a database table. + * + * It defines a set of methods to retrieve the table name, schema name, column names, primary key, foreign keys, etc. + * + * The information is obtained from the database schema and may vary according to the DBMS type. */ interface TableSchemaInterface { /** * Gets the named column metadata. * - * This is a convenient method for retrieving a named column even if it does not exist. + * This is a convenient method for retrieving a named column even if it doesn't exist. * * @param string $name The column name. * - * @return ColumnSchemaInterface|null The named column metadata. Null if the named column does not exist. + * @return ColumnSchemaInterface|null The named column metadata. Null if the named column doesn't exist. */ public function getColumn(string $name): ColumnSchemaInterface|null; @@ -40,14 +42,14 @@ public function getComment(): string|null; public function getSchemaName(): string|null; /** - * @return string The name of this table. The schema name is not included. Use {@see fullName} to get the name with + * @return string The name of this table. The schema name isn't included. Use {@see fullName} to get the name with * schema name prefix. */ public function getName(): string; /** * @return string|null The full name of this table, which includes the schema name prefix, if any. Note that if the - * schema name is the same as the {@see Schema::defaultSchema} schema name, the schema name will not be included. + * schema name is the same as the {@see Schema::defaultSchema} schema name, the schema name won't be included. */ public function getFullName(): string|null; @@ -79,8 +81,9 @@ public function getColumns(): array; public function schemaName(string|null $value): void; /** - * Set name of this table. The schema name is not included. Use {@see fullName} to set the name with schema name - * prefix. + * Set the name of this table. + * + * The schema name isn't included. Use {@see fullName} to set the name with schema name prefix. * * @param string $value The name of this table. */ @@ -88,14 +91,16 @@ public function name(string $value): void; /** * Set the full name of this table, which includes the schema name prefix, if any. Note that if the schema name is - * the same as the {@see Schema::defaultSchema} schema name, the schema name will not be included. + * the same as the {@see Schema::defaultSchema} schema name, the schema name won't be included. * * @param string|null $value The full name of this table. */ public function fullName(string|null $value): void; /** - * Set the comment of the table. Null if no comment. This is not supported by all DBMS. + * Set the comment of the table. + * + * Null if no comment. This isn't supported by all DBMS. * * @param string|null $value The comment of the table. */ @@ -125,7 +130,9 @@ public function columns(string $index, ColumnSchemaInterface $value): void; /** * @return string|null The name of the catalog (database) that this table belongs to. Defaults to null, meaning no - * catalog (or the current database). Specifically for MSSQL Server + * catalog (or the current database). + * + * Specifically for MSSQL Server */ public function getCatalogName(): string|null; @@ -139,7 +146,9 @@ public function catalogName(string|null $value): void; /** * @return string|null The name of the server that this table belongs to. Defaults to null, meaning no server - * (or the current server). Specifically for MSSQL Server + * (or the current server). + * + * Specifically for MSSQL Server */ public function getServerName(): string|null; @@ -152,15 +161,15 @@ public function getServerName(): string|null; public function serverName(string|null $value): void; /** - * @return string|null The sql for create current table or null if query not found/exists. Now supported only in + * @return string|null The sql for create current table or null if a query not found/exists. Now supported only in * MySQL and Oracle DBMS. */ public function getCreateSql(): string|null; /** - * Set sql for create current table or null if query not found/exists. Now supported only in MySQL and Oracle DBMS. + * Set sql for create current table or null if a query not found/exists. Now supported only in MySQL and Oracle DBMS. * - * @param string $sql The sql for create current table or null if query not found/exists. + * @param string $sql The sql for create current table or null if a query not found/exists. */ public function createSql(string $sql): void;