From 4c187847dcd3dfa8b92b413db0ffe2549636128d Mon Sep 17 00:00:00 2001
From: catch <catch56@gmail.com>
Date: Mon, 24 Oct 2022 15:57:12 +0100
Subject: [PATCH] Issue #3316950 by mondrake: Fix StreamWrapper\ReadOnlyStream
 PHPStan-0 issues

---
 .../Core/StreamWrapper/ReadOnlyStream.php     | 30 +++++++++++++++++++
 core/phpstan-baseline.neon                    |  5 ----
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
index a2fa80436348..65e0d98a7fd9 100644
--- a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
@@ -68,6 +68,9 @@ public function getUri() {
    *   TRUE if $mode denotes a readonly mode and the file was opened
    *   successfully, FALSE otherwise.
    *
+   * @throws \BadMethodCallException
+   *   When ::getLocalPath() is not implemented in the concrete driver class.
+   *
    * @see http://php.net/manual/streamwrapper.stream-open.php
    */
   public function stream_open($uri, $mode, $options, &$opened_path) {
@@ -89,6 +92,33 @@ public function stream_open($uri, $mode, $options, &$opened_path) {
     return (bool) $this->handle;
   }
 
+  /**
+   * Returns the canonical absolute path of the URI, if possible.
+   *
+   * @param string $uri
+   *   (optional) The stream wrapper URI to be converted to a canonical
+   *   absolute path. This may point to a directory or another type of file.
+   *
+   * @return string|bool
+   *   If $uri is not set, returns the canonical absolute path of the URI
+   *   previously set by the
+   *   Drupal\Core\StreamWrapper\StreamWrapperInterface::setUri() function.
+   *   If $uri is set and valid for this class, returns its canonical absolute
+   *   path, as determined by the realpath() function. If $uri is set but not
+   *   valid, returns FALSE.
+   *
+   * @throws \BadMethodCallException
+   *   If the method is not implemented in the concrete driver class.
+   *
+   * @todo This method is called by ReadOnlyStream::stream_open on the abstract
+   *   class, and therefore should be defined as well on the abstract class to
+   *   prevent static analysis errors. In D11, consider changing it to an
+   *   abstract method.
+   */
+  protected function getLocalPath($uri = NULL) {
+    throw new \BadMethodCallException(get_class($this) . '::getLocalPath() not implemented.');
+  }
+
   /**
    * Support for flock().
    *
diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon
index 10ac55102806..3a6e2d730cf1 100644
--- a/core/phpstan-baseline.neon
+++ b/core/phpstan-baseline.neon
@@ -355,11 +355,6 @@ parameters:
 			count: 1
 			path: lib/Drupal/Core/Session/SessionManager.php
 
-		-
-			message: "#^Call to an undefined method Drupal\\\\Core\\\\StreamWrapper\\\\ReadOnlyStream\\:\\:getLocalPath\\(\\)\\.$#"
-			count: 1
-			path: lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
-
 		-
 			message: "#^Method Drupal\\\\Core\\\\Template\\\\AttributeValueBase\\:\\:render\\(\\) should return string but return statement is missing\\.$#"
 			count: 1
-- 
GitLab