diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index c65ff3b9d88f529ad004aa7b33d890fe102ca27e..f28f60a521026bce85946f3d866c7de6fb1861d7 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -1112,7 +1112,7 @@ public function transactionManager(): TransactionManagerInterface { * @throws \LogicException * If the transaction manager is undefined or unavailable. */ - // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn + // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn, Drupal.Commenting.FunctionComment.Missing protected function driverTransactionManager(): TransactionManagerInterface { throw new \LogicException('The database driver has no TransactionManager implementation'); } diff --git a/core/lib/Drupal/Core/Database/Schema.php b/core/lib/Drupal/Core/Database/Schema.php index 434120ef1839d1640de17422bbf0739c55f33bba..3a96fe9b6966cf1483fa4383dcbcf79df720c03f 100644 --- a/core/lib/Drupal/Core/Database/Schema.php +++ b/core/lib/Drupal/Core/Database/Schema.php @@ -547,7 +547,7 @@ abstract public function dropIndex($table, $name); * @throws \RuntimeException * If the driver does not implement this method. */ - // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn + // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn, Drupal.Commenting.FunctionComment.Missing protected function introspectIndexSchema($table) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException("The table $table doesn't exist."); @@ -668,7 +668,7 @@ public function createTable($name, $table) { * make it private for each driver, and ::createTable actually an abstract * method here for implementation in each driver. */ - // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn + // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn, Drupal.Commenting.FunctionComment.Missing protected function createTableSql($name, $table) { throw new \BadMethodCallException(get_class($this) . '::createTableSql() not implemented.'); } diff --git a/core/modules/mysql/src/Driver/Database/mysql/Connection.php b/core/modules/mysql/src/Driver/Database/mysql/Connection.php index acc087419128b2ca9848d5290b23b97e9da75cec..bd4fb0ba3ccbc19c3901efcbe03328eebfec15ad 100644 --- a/core/modules/mysql/src/Driver/Database/mysql/Connection.php +++ b/core/modules/mysql/src/Driver/Database/mysql/Connection.php @@ -212,6 +212,9 @@ public static function open(array &$connection_options = []) { return $pdo; } + /** + * {@inheritdoc} + */ public function queryRange($query, $from, $count, array $args = [], array $options = []) { return $this->query($query . ' LIMIT ' . (int) $from . ', ' . (int) $count, $args, $options); } @@ -225,6 +228,9 @@ public function queryTemporary($query, array $args = [], array $options = []) { return $tablename; } + /** + * {@inheritdoc} + */ public function driver() { return 'mysql'; } @@ -279,6 +285,9 @@ protected function getServerVersion(): string { return $this->serverVersion; } + /** + * {@inheritdoc} + */ public function databaseType() { return 'mysql'; } @@ -305,6 +314,9 @@ public function createDatabase($database) { } } + /** + * {@inheritdoc} + */ public function mapConditionOperator($operator) { // We don't want to override any of the defaults. return NULL; diff --git a/core/modules/mysql/src/Driver/Database/mysql/Insert.php b/core/modules/mysql/src/Driver/Database/mysql/Insert.php index 6db8e4f61279227b8337546fb87a902a93aa937f..cc9029a6154ca7eb9b4e6a8b493d60443c1a671c 100644 --- a/core/modules/mysql/src/Driver/Database/mysql/Insert.php +++ b/core/modules/mysql/src/Driver/Database/mysql/Insert.php @@ -9,6 +9,9 @@ */ class Insert extends QueryInsert { + /** + * {@inheritdoc} + */ public function execute() { if (!$this->preExecute()) { return NULL; @@ -44,6 +47,9 @@ public function execute() { return $last_insert_id; } + /** + * {@inheritdoc} + */ public function __toString() { // Create a sanitized comment string to prepend to the query. $comments = $this->connection->makeComment($this->comments); diff --git a/core/modules/mysql/src/Driver/Database/mysql/Schema.php b/core/modules/mysql/src/Driver/Database/mysql/Schema.php index e7b454b3ba31cc411bc220b5bccb6b83efc998a1..351f4180821e18e47e4eaff1d855e8c52e7f658e 100644 --- a/core/modules/mysql/src/Driver/Database/mysql/Schema.php +++ b/core/modules/mysql/src/Driver/Database/mysql/Schema.php @@ -271,6 +271,9 @@ public function getFieldTypeMap() { return $map; } + /** + * Creates the keys for an SQL table. + */ protected function createKeysSql($spec) { $keys = []; @@ -355,6 +358,9 @@ protected function shortenIndex(&$index) { } } + /** + * Creates an SQL key for the given fields. + */ protected function createKeySql($fields) { $return = []; foreach ($fields as $field) { diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php index 88714b01bc574131ec59a92ed0398b019009d71f..ae49ae9890b9524329fb8289f51fd7d87fe05291 100644 --- a/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php @@ -255,6 +255,9 @@ public function prepareStatement(string $query, array $options, bool $allow_row_ return parent::prepareStatement($query, $options, $allow_row_count); } + /** + * {@inheritdoc} + */ public function queryRange($query, $from, $count, array $args = [], array $options = []) { return $this->query($query . ' LIMIT ' . (int) $count . ' OFFSET ' . (int) $from, $args, $options); } @@ -268,10 +271,16 @@ public function queryTemporary($query, array $args = [], array $options = []) { return $tablename; } + /** + * {@inheritdoc} + */ public function driver() { return 'pgsql'; } + /** + * {@inheritdoc} + */ public function databaseType() { return 'pgsql'; } @@ -318,6 +327,9 @@ public function createDatabase($database) { } } + /** + * {@inheritdoc} + */ public function mapConditionOperator($operator) { return static::$postgresqlConditionOperatorMap[$operator] ?? NULL; } diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Insert.php b/core/modules/pgsql/src/Driver/Database/pgsql/Insert.php index 675f4b9c314f510e03ccd552bdcb913b3c7eb0d3..223daeb8d8ab06e9d9108971b906a88b99d639f0 100644 --- a/core/modules/pgsql/src/Driver/Database/pgsql/Insert.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Insert.php @@ -17,6 +17,9 @@ */ class Insert extends QueryInsert { + /** + * {@inheritdoc} + */ public function execute() { if (!$this->preExecute()) { return NULL; @@ -102,6 +105,9 @@ public function execute() { return $last_insert_id ?? NULL; } + /** + * {@inheritdoc} + */ public function __toString() { // Create a sanitized comment string to prepend to the query. $comments = $this->connection->makeComment($this->comments); diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php index 2a8e10da65d73767ab303cf929ca6835e4f1e0c5..7e475245f2f0f79335a66a97e683785528c05046 100644 --- a/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php @@ -471,6 +471,9 @@ public function getFieldTypeMap() { return $map; } + /** + * Creates the SQL key for the given fields. + */ protected function _createKeySql($fields) { $return = []; foreach ($fields as $field) { @@ -1020,12 +1023,18 @@ public function changeField($table, $field, $field_new, $spec, $new_keys = []) { $this->resetTableInformation($table); } + /** + * Creates a statement for an SQL index for the given fields. + */ protected function _createIndexSql($table, $name, $fields) { $query = 'CREATE INDEX ' . $this->ensureIdentifiersLength($table, $name, 'idx') . ' ON {' . $table . '} ('; $query .= $this->_createKeySql($fields) . ')'; return $query; } + /** + * Adds keys for an SQL table. + */ protected function _createKeys($table, $new_keys) { if (isset($new_keys['primary key'])) { $this->addPrimaryKey($table, $new_keys['primary key']); diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Select.php b/core/modules/pgsql/src/Driver/Database/pgsql/Select.php index 26a0e0feb48af1e4acab5ebdd59a94d43f0a1e1d..ac3adaceaa5946fac1a8bd586da440cdc3a7f9f4 100644 --- a/core/modules/pgsql/src/Driver/Database/pgsql/Select.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Select.php @@ -14,6 +14,9 @@ */ class Select extends QuerySelect { + /** + * {@inheritdoc} + */ public function orderRandom() { $alias = $this->addExpression('RANDOM()', 'random_field'); $this->orderBy($alias); diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Update.php b/core/modules/pgsql/src/Driver/Database/pgsql/Update.php index d3f2ebf6431d7b844863701efed9190d2ac6b69e..0b4f9a0f4f6f42cce2d9aeae8b3fec0985f15445 100644 --- a/core/modules/pgsql/src/Driver/Database/pgsql/Update.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Update.php @@ -10,6 +10,9 @@ */ class Update extends QueryUpdate { + /** + * {@inheritdoc} + */ public function execute() { $max_placeholder = 0; $blobs = []; diff --git a/core/modules/sqlite/src/Driver/Database/sqlite/Connection.php b/core/modules/sqlite/src/Driver/Database/sqlite/Connection.php index 53c2fa0c1fe0f45dd57ffb10e5be232d11434234..964fa80c9c9ab901caf6b9eadb05e832191fdc56 100644 --- a/core/modules/sqlite/src/Driver/Database/sqlite/Connection.php +++ b/core/modules/sqlite/src/Driver/Database/sqlite/Connection.php @@ -347,6 +347,9 @@ public static function sqlFunctionLikeBinary($pattern, $subject) { return preg_match('/^' . $pattern . '$/', $subject); } + /** + * {@inheritdoc} + */ public function queryRange($query, $from, $count, array $args = [], array $options = []) { return $this->query($query . ' LIMIT ' . (int) $from . ', ' . (int) $count, $args, $options); } @@ -367,10 +370,16 @@ public function queryTemporary($query, array $args = [], array $options = []) { return 'temp.' . $tablename; } + /** + * {@inheritdoc} + */ public function driver() { return 'sqlite'; } + /** + * {@inheritdoc} + */ public function databaseType() { return 'sqlite'; } @@ -391,6 +400,9 @@ public function createDatabase($database) { } } + /** + * {@inheritdoc} + */ public function mapConditionOperator($operator) { return static::$sqliteConditionOperatorMap[$operator] ?? NULL; } diff --git a/core/modules/sqlite/src/Driver/Database/sqlite/Select.php b/core/modules/sqlite/src/Driver/Database/sqlite/Select.php index 5ee521af8b22e24b27327b44245449d1b80654a9..f8471d0609c8db360f3586af330b4ef3f235da20 100644 --- a/core/modules/sqlite/src/Driver/Database/sqlite/Select.php +++ b/core/modules/sqlite/src/Driver/Database/sqlite/Select.php @@ -9,6 +9,9 @@ */ class Select extends QuerySelect { + /** + * {@inheritdoc} + */ public function forUpdate($set = TRUE) { // SQLite does not support FOR UPDATE so nothing to do. return $this; diff --git a/core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php b/core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php index f1535fb0196d8e5894b607c581d697d4a5f0518e..29d82f47792139470f21041a3df64485d645464f 100644 --- a/core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php +++ b/core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php @@ -12,6 +12,9 @@ */ class Truncate extends QueryTruncate { + /** + * {@inheritdoc} + */ public function __toString() { // Create a sanitized comment string to prepend to the query. $comments = $this->connection->makeComment($this->comments); diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index 408b834d3370c0722f860a8b320efe568290da5f..887121e72fa0de1001cb28e38cb787713b0ac058 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -78,6 +78,7 @@ <include-pattern>core/modules/*/Plugin/views/display/*</include-pattern> <include-pattern>core/modules/*/Plugin/views/exposed_form/*</include-pattern> <include-pattern>core/modules/*/Plugin/views/field/*</include-pattern> + <include-pattern>*/Database/*</include-pattern> <exclude-pattern>*/tests/*</exclude-pattern> </rule> <rule ref="Drupal.Commenting.FunctionComment.MissingParamType"> diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectLeastTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectLeastTest.php index a67976589ecbed48d9000d552c9d442622ac418b..08b69048d547076cb6abc3627d63e90732582edc 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SelectLeastTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SelectLeastTest.php @@ -21,6 +21,9 @@ public function testSelectLeast($values, $expected): void { $this->assertEquals($expected, $least); } + /** + * Provides data for testing the LEAST operator. + */ public static function selectLeastProvider() { return [ [[1, 2, 3, 4, 5, 6], 1], diff --git a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php index 9cda46bd7b3070bcb2efc993f4e6ee4484509273..7ef2e4fd4fc0af915139a230c33f78b288d2eb54 100644 --- a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php @@ -175,6 +175,9 @@ public function testCompileWithSqlInjectionForOperator($operator): void { $condition->compile($connection, $query_placeholder); } + /** + * Provides data for testing SQL injection. + */ public static function providerTestCompileWithSqlInjectionForOperator() { $data = []; $data[] = ["IS NOT NULL) ;INSERT INTO {test} (name) VALUES ('test12345678'); -- "];