From f29ceb64c2a9f6e38ef3495b091d673fc14de151 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 1 Feb 2022 12:42:01 +0000
Subject: [PATCH] Issue #3259110 by longwave, mglaman: Fix undefined variables
 where files are included

---
 .../Transliteration/PhpTransliteration.php        | 10 ++--------
 core/modules/color/color.module                   |  1 +
 core/phpstan-baseline.neon                        | 15 ---------------
 3 files changed, 3 insertions(+), 23 deletions(-)

diff --git a/core/lib/Drupal/Component/Transliteration/PhpTransliteration.php b/core/lib/Drupal/Component/Transliteration/PhpTransliteration.php
index 977892ddabf4..3f1d9253da85 100644
--- a/core/lib/Drupal/Component/Transliteration/PhpTransliteration.php
+++ b/core/lib/Drupal/Component/Transliteration/PhpTransliteration.php
@@ -283,12 +283,10 @@ protected function readLanguageOverrides($langcode) {
 
     // Read in this file, which should set up a variable called $overrides,
     // which will be local to this function.
+    $overrides[$langcode] = [];
     if (is_file($file)) {
       include $file;
     }
-    if (!isset($overrides) || !is_array($overrides)) {
-      $overrides = [$langcode => []];
-    }
     $this->languageOverrides[$langcode] = $overrides[$langcode];
   }
 
@@ -311,14 +309,10 @@ protected function readGenericData($bank) {
 
     // Read in this file, which should set up a variable called $base, which
     // will be local to this function.
+    $base = [];
     if (is_file($file)) {
       include $file;
     }
-    if (!isset($base) || !is_array($base)) {
-      $base = [];
-    }
-
-    // Save this data.
     $this->genericMap[$bank] = $base;
   }
 
diff --git a/core/modules/color/color.module b/core/modules/color/color.module
index 8a8aa5e1b41c..6d854eeff9e4 100644
--- a/core/modules/color/color.module
+++ b/core/modules/color/color.module
@@ -132,6 +132,7 @@ function color_get_info($theme) {
   $path = \Drupal::service('extension.list.theme')->getPath($theme);
   $file = \Drupal::root() . '/' . $path . '/color/color.inc';
   if ($path && file_exists($file)) {
+    $info = [];
     include $file;
     // Add in default values.
     $info += [
diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon
index ed1f1e98a865..2e51d88f10e5 100644
--- a/core/phpstan-baseline.neon
+++ b/core/phpstan-baseline.neon
@@ -20,16 +20,6 @@ parameters:
 			count: 1
 			path: includes/update.inc
 
-		-
-			message: "#^Undefined variable\\: \\$base$#"
-			count: 1
-			path: lib/Drupal/Component/Transliteration/PhpTransliteration.php
-
-		-
-			message: "#^Undefined variable\\: \\$overrides$#"
-			count: 1
-			path: lib/Drupal/Component/Transliteration/PhpTransliteration.php
-
 		-
 			message: "#^Call to method getDefinitions\\(\\) on an unknown class Drupal\\\\Core\\\\Plugin\\\\CategorizingPluginManagerTrait\\.$#"
 			count: 3
@@ -300,11 +290,6 @@ parameters:
 			count: 1
 			path: modules/ckeditor5/src/Controller/CKEditor5ImageController.php
 
-		-
-			message: "#^Undefined variable\\: \\$info$#"
-			count: 1
-			path: modules/color/color.module
-
 		-
 			message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:10\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
 			count: 1
-- 
GitLab