From 6eda609d2b3d8fb958c759a6ce7cd86ed80df4c1 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 3 Jan 2025 10:50:26 +1000
Subject: [PATCH] Issue #3491222 by quietone: Fix
 Drupal.Commenting.FunctionComment.Missing in Database files

---
 core/lib/Drupal/Core/Database/Connection.php         |  2 +-
 core/lib/Drupal/Core/Database/Schema.php             |  4 ++--
 .../mysql/src/Driver/Database/mysql/Connection.php   | 12 ++++++++++++
 .../mysql/src/Driver/Database/mysql/Insert.php       |  6 ++++++
 .../mysql/src/Driver/Database/mysql/Schema.php       |  6 ++++++
 .../pgsql/src/Driver/Database/pgsql/Connection.php   | 12 ++++++++++++
 .../pgsql/src/Driver/Database/pgsql/Insert.php       |  6 ++++++
 .../pgsql/src/Driver/Database/pgsql/Schema.php       |  9 +++++++++
 .../pgsql/src/Driver/Database/pgsql/Select.php       |  3 +++
 .../pgsql/src/Driver/Database/pgsql/Update.php       |  3 +++
 .../sqlite/src/Driver/Database/sqlite/Connection.php | 12 ++++++++++++
 .../sqlite/src/Driver/Database/sqlite/Select.php     |  3 +++
 .../sqlite/src/Driver/Database/sqlite/Truncate.php   |  3 +++
 core/phpcs.xml.dist                                  |  1 +
 .../KernelTests/Core/Database/SelectLeastTest.php    |  3 +++
 .../Drupal/Tests/Core/Database/ConditionTest.php     |  3 +++
 16 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php
index c65ff3b9d88f..f28f60a52102 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 434120ef1839..3a96fe9b6966 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 acc087419128..bd4fb0ba3ccb 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 6db8e4f61279..cc9029a6154c 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 e7b454b3ba31..351f4180821e 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 88714b01bc57..ae49ae9890b9 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 675f4b9c314f..223daeb8d8ab 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 2a8e10da65d7..7e475245f2f0 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 26a0e0feb48a..ac3adaceaa59 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 d3f2ebf6431d..0b4f9a0f4f6f 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 53c2fa0c1fe0..964fa80c9c9a 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 5ee521af8b22..f8471d0609c8 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 f1535fb0196d..29d82f477921 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 408b834d3370..887121e72fa0 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 a67976589ecb..08b69048d547 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 9cda46bd7b30..7ef2e4fd4fc0 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'); -- "];
-- 
GitLab