From 7d8dd96f524b2fe1a496e0b10fb607a484372dd9 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Thu, 19 Dec 2024 10:37:02 +1000
Subject: [PATCH] Issue #3396846 by quietone, Aditi Saraf, mstrelan: Enable
 Drupal.Commenting.FunctionComment.InvalidNoReturn

---
 core/.phpstan-baseline.php                    | 24 -------------------
 .../Component/Plugin/PluginManagerBase.php    |  1 +
 core/lib/Drupal/Core/Database/Connection.php  |  1 +
 core/lib/Drupal/Core/Database/Schema.php      |  2 ++
 .../Field/FieldWidget/OptionsWidgetBase.php   |  4 +++-
 .../Drupal/Core/FileTransfer/FileTransfer.php |  1 +
 .../Core/StreamWrapper/ReadOnlyStream.php     |  1 +
 .../Plugin/Field/FieldType/ListFloatItem.php  |  1 +
 .../Field/FieldType/ListIntegerItem.php       |  1 +
 .../Plugin/Field/FieldType/ListItemBase.php   |  6 +++--
 .../Plugin/Field/FieldType/ListStringItem.php |  1 +
 .../ArgumentValidatorPluginBase.php           |  4 +++-
 core/phpcs.xml.dist                           |  1 -
 13 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php
index 112c18567677..9968def98e34 100644
--- a/core/.phpstan-baseline.php
+++ b/core/.phpstan-baseline.php
@@ -31380,18 +31380,6 @@
 	'count' => 1,
 	'path' => __DIR__ . '/modules/options/src/Hook/OptionsHooks.php',
 ];
-$ignoreErrors[] = [
-	// identifier: return.missing
-	'message' => '#^Method Drupal\\\\options\\\\Plugin\\\\Field\\\\FieldType\\\\ListFloatItem\\:\\:validateAllowedValue\\(\\) should return string but return statement is missing\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php',
-];
-$ignoreErrors[] = [
-	// identifier: return.missing
-	'message' => '#^Method Drupal\\\\options\\\\Plugin\\\\Field\\\\FieldType\\\\ListIntegerItem\\:\\:validateAllowedValue\\(\\) should return string but return statement is missing\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php',
-];
 $ignoreErrors[] = [
 	// identifier: property.notFound
 	'message' => '#^Access to an undefined property Drupal\\\\options\\\\Plugin\\\\Field\\\\FieldType\\\\ListItemBase\\:\\:\\$value\\.$#',
@@ -31428,24 +31416,12 @@
 	'count' => 1,
 	'path' => __DIR__ . '/modules/options/src/Plugin/Field/FieldType/ListItemBase.php',
 ];
-$ignoreErrors[] = [
-	// identifier: return.missing
-	'message' => '#^Method Drupal\\\\options\\\\Plugin\\\\Field\\\\FieldType\\\\ListItemBase\\:\\:validateAllowedValue\\(\\) should return string but return statement is missing\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/options/src/Plugin/Field/FieldType/ListItemBase.php',
-];
 $ignoreErrors[] = [
 	// identifier: missingType.return
 	'message' => '#^Method Drupal\\\\options\\\\Plugin\\\\Field\\\\FieldType\\\\ListItemBase\\:\\:validateAllowedValues\\(\\) has no return type specified\\.$#',
 	'count' => 1,
 	'path' => __DIR__ . '/modules/options/src/Plugin/Field/FieldType/ListItemBase.php',
 ];
-$ignoreErrors[] = [
-	// identifier: return.missing
-	'message' => '#^Method Drupal\\\\options\\\\Plugin\\\\Field\\\\FieldType\\\\ListStringItem\\:\\:validateAllowedValue\\(\\) should return string but return statement is missing\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/modules/options/src/Plugin/Field/FieldType/ListStringItem.php',
-];
 $ignoreErrors[] = [
 	// identifier: missingType.return
 	'message' => '#^Method Drupal\\\\options\\\\Plugin\\\\views\\\\argument\\\\NumberListField\\:\\:buildOptionsForm\\(\\) has no return type specified\\.$#',
diff --git a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php
index 7467915ea53f..d95bbf032702 100644
--- a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php
+++ b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php
@@ -124,6 +124,7 @@ protected function handlePluginNotFound($plugin_id, array $configuration) {
    * @throws \BadMethodCallException
    *   If the method is not implemented in the concrete plugin manager class.
    */
+  // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn
   protected function getFallbackPluginId($plugin_id, array $configuration = []) {
     throw new \BadMethodCallException(static::class . '::getFallbackPluginId() not implemented.');
   }
diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php
index 7a9de46a7d41..830d923b2936 100644
--- a/core/lib/Drupal/Core/Database/Connection.php
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -1110,6 +1110,7 @@ public function transactionManager(): TransactionManagerInterface {
    * @throws \LogicException
    *   If the transaction manager is undefined or unavailable.
    */
+  // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn
   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 7b5d585de940..a22a449a10a0 100644
--- a/core/lib/Drupal/Core/Database/Schema.php
+++ b/core/lib/Drupal/Core/Database/Schema.php
@@ -547,6 +547,7 @@ abstract public function dropIndex($table, $name);
    * @throws \RuntimeException
    *   If the driver does not implement this method.
    */
+  // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn
   protected function introspectIndexSchema($table) {
     if (!$this->tableExists($table)) {
       throw new SchemaObjectDoesNotExistException("The table $table doesn't exist.");
@@ -667,6 +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
   protected function createTableSql($name, $table) {
     throw new \BadMethodCallException(get_class($this) . '::createTableSql() not implemented.');
   }
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
index 29a2041fd437..60920fad60f5 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
@@ -222,6 +222,8 @@ protected function sanitizeLabel(&$label) {
    * @return string|null
    *   Either a label of the empty option, or NULL.
    */
-  protected function getEmptyLabel() {}
+  protected function getEmptyLabel() {
+    return NULL;
+  }
 
 }
diff --git a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php
index af4951bfa464..cd0b7da274e9 100644
--- a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php
+++ b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php
@@ -88,6 +88,7 @@ public function __construct($jail) {
    *
    * @throws \Drupal\Core\FileTransfer\FileTransferException
    */
+  // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn
   public static function factory($jail, $settings) {
     throw new FileTransferException('FileTransfer::factory() static method not overridden by FileTransfer subclass.');
   }
diff --git a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
index 65e0d98a7fd9..396227525506 100644
--- a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
@@ -115,6 +115,7 @@ public function stream_open($uri, $mode, $options, &$opened_path) {
    *   prevent static analysis errors. In D11, consider changing it to an
    *   abstract method.
    */
+  // phpcs:ignore Drupal.Commenting.FunctionComment.InvalidNoReturn
   protected function getLocalPath($uri = NULL) {
     throw new \BadMethodCallException(get_class($this) . '::getLocalPath() not implemented.');
   }
diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php
index ec213b08876c..eff807293452 100644
--- a/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php
+++ b/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php
@@ -89,6 +89,7 @@ protected static function validateAllowedValue($option) {
     if (!is_numeric($option)) {
       return new TranslatableMarkup('Allowed values list: each key must be a valid integer or decimal.');
     }
+    return NULL;
   }
 
   /**
diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php
index f053b101039c..c4e9c7d0d363 100644
--- a/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php
+++ b/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php
@@ -70,6 +70,7 @@ protected static function validateAllowedValue($option) {
     if (!preg_match('/^-?\d+$/', $option)) {
       return new TranslatableMarkup('Allowed values list: keys must be integers.');
     }
+    return NULL;
   }
 
   /**
diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
index 47f1705481b1..250fe8812eaf 100644
--- a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
+++ b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
@@ -444,10 +444,12 @@ protected static function extractAllowedValues(array $list, bool $has_data) {
    * @param string $option
    *   The option value entered by the user.
    *
-   * @return string
+   * @return \Drupal\Core\StringTranslation\TranslatableMarkup|string|null
    *   The error message if the specified value is invalid, NULL otherwise.
    */
-  protected static function validateAllowedValue($option) {}
+  protected static function validateAllowedValue($option) {
+    return NULL;
+  }
 
   /**
    * Generates a string representation of an array of 'allowed values'.
diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php
index 332a1768c23e..c31f1bc13768 100644
--- a/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php
+++ b/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php
@@ -74,6 +74,7 @@ protected static function validateAllowedValue($option) {
     if (mb_strlen($option) > 255) {
       return new TranslatableMarkup('Allowed values list: each key must be a string at most 255 characters long.');
     }
+    return NULL;
   }
 
   /**
diff --git a/core/modules/views/src/Plugin/views/argument_validator/ArgumentValidatorPluginBase.php b/core/modules/views/src/Plugin/views/argument_validator/ArgumentValidatorPluginBase.php
index 80cd882e24a4..fcb3618d5665 100644
--- a/core/modules/views/src/Plugin/views/argument_validator/ArgumentValidatorPluginBase.php
+++ b/core/modules/views/src/Plugin/views/argument_validator/ArgumentValidatorPluginBase.php
@@ -123,7 +123,9 @@ public function processSummaryArguments(&$args) {}
    *   A context definition that represents the argument or NULL if that is
    *   not possible.
    */
-  public function getContextDefinition() {}
+  public function getContextDefinition() {
+    return NULL;
+  }
 
 }
 
diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist
index 733c8d5084ea..d7a66fe42aa4 100644
--- a/core/phpcs.xml.dist
+++ b/core/phpcs.xml.dist
@@ -68,7 +68,6 @@
   <rule ref="Drupal.Commenting.FileComment"/>
 
   <rule ref="Drupal.Commenting.FunctionComment">
-    <exclude name="Drupal.Commenting.FunctionComment.InvalidNoReturn"/>
     <exclude name="Drupal.Commenting.FunctionComment.Missing"/>
     <exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>
     <exclude name="Drupal.Commenting.FunctionComment.ParamCommentFullStop"/>
-- 
GitLab