From 511d6fe569410f477e94f88a3a73b0b05b5c2ab6 Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Tue, 23 Jul 2024 14:00:25 +0100
Subject: [PATCH] Issue #3459170 by mstrelan: Fix instances of ints passed to
 functions expecting strings

(cherry picked from commit e3b52e2f3f3f6b9177bc93bb8fa4415dc56444bf)
---
 core/lib/Drupal/Component/Utility/Color.php                     | 2 +-
 core/lib/Drupal/Component/Utility/Number.php                    | 2 +-
 .../Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php    | 2 +-
 .../Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php | 2 +-
 core/lib/Drupal/Core/Lock/LockBackendAbstract.php               | 2 +-
 core/lib/Drupal/Core/Lock/NullLockBackend.php                   | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/core/lib/Drupal/Component/Utility/Color.php b/core/lib/Drupal/Component/Utility/Color.php
index 8aeb9f61341a..49d0aa256033 100644
--- a/core/lib/Drupal/Component/Utility/Color.php
+++ b/core/lib/Drupal/Component/Utility/Color.php
@@ -84,7 +84,7 @@ public static function rgbToHex($input) {
       $out |= $v << (16 - $k * 8);
     }
 
-    return '#' . str_pad(dechex($out), 6, 0, STR_PAD_LEFT);
+    return '#' . str_pad(dechex($out), 6, '0', STR_PAD_LEFT);
   }
 
   /**
diff --git a/core/lib/Drupal/Component/Utility/Number.php b/core/lib/Drupal/Component/Utility/Number.php
index 838c33c454f9..2fcbc0b2e759 100644
--- a/core/lib/Drupal/Component/Utility/Number.php
+++ b/core/lib/Drupal/Component/Utility/Number.php
@@ -77,7 +77,7 @@ public static function validStep($value, $step, $offset = 0.0) {
    * @see \Drupal\Component\Utility\Number::alphadecimalToInt
    */
   public static function intToAlphadecimal($i = 0) {
-    $num = base_convert((int) $i, 10, 36);
+    $num = base_convert((string) $i, 10, 36);
     $length = strlen($num);
 
     return chr($length + ord('0') - 1) . $num;
diff --git a/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php
index e2e23636ed1f..de352305d37e 100644
--- a/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php
@@ -152,7 +152,7 @@ public function onException(ExceptionEvent $event) {
    */
   public function on4xx(ExceptionEvent $event) {
     $exception = $event->getThrowable();
-    if ($exception && $exception instanceof HttpExceptionInterface && str_starts_with($exception->getStatusCode(), '4')) {
+    if ($exception && $exception instanceof HttpExceptionInterface && str_starts_with((string) $exception->getStatusCode(), '4')) {
       $message = PlainTextOutput::renderFromHtml($exception->getMessage());
       // If the exception is cacheable, generate a cacheable response.
       if ($exception instanceof CacheableDependencyInterface) {
diff --git a/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php b/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php
index 9ace7c25292c..c6ba29ac1924 100644
--- a/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php
+++ b/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php
@@ -100,7 +100,7 @@ public function onException(ExceptionEvent $event) {
       $method = 'on' . $exception->getStatusCode();
       // Keep just the leading number of the status code to produce either a
       // 400 or a 500 method callback.
-      $method_fallback = 'on' . substr($exception->getStatusCode(), 0, 1) . 'xx';
+      $method_fallback = 'on' . substr((string) $exception->getStatusCode(), 0, 1) . 'xx';
       // We want to allow the method to be called and still not set a response
       // if it has additional filtering logic to determine when it will apply.
       // It is therefore the method's responsibility to set the response on the
diff --git a/core/lib/Drupal/Core/Lock/LockBackendAbstract.php b/core/lib/Drupal/Core/Lock/LockBackendAbstract.php
index 41ee27cab4f8..4fe6c6d65a83 100644
--- a/core/lib/Drupal/Core/Lock/LockBackendAbstract.php
+++ b/core/lib/Drupal/Core/Lock/LockBackendAbstract.php
@@ -67,7 +67,7 @@ public function wait($name, $delay = 30) {
    */
   public function getLockId() {
     if (!isset($this->lockId)) {
-      $this->lockId = uniqid(mt_rand(), TRUE);
+      $this->lockId = uniqid((string) mt_rand(), TRUE);
     }
     return $this->lockId;
   }
diff --git a/core/lib/Drupal/Core/Lock/NullLockBackend.php b/core/lib/Drupal/Core/Lock/NullLockBackend.php
index 65bf65a1b15b..ad3be11f2c2b 100644
--- a/core/lib/Drupal/Core/Lock/NullLockBackend.php
+++ b/core/lib/Drupal/Core/Lock/NullLockBackend.php
@@ -53,7 +53,7 @@ public function releaseAll($lock_id = NULL) {}
    */
   public function getLockId() {
     if (!isset($this->lockId)) {
-      $this->lockId = uniqid(mt_rand(), TRUE);
+      $this->lockId = uniqid((string) mt_rand(), TRUE);
     }
     return $this->lockId;
   }
-- 
GitLab