From eeaaccc17e7006e2ebadfb86712dd0982ed210ba Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 24 Oct 2022 15:57:12 +0100 Subject: [PATCH] Issue #3316950 by mondrake: Fix StreamWrapper\ReadOnlyStream PHPStan-0 issues (cherry picked from commit 4c187847dcd3dfa8b92b413db0ffe2549636128d) --- .../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 a2fa8043634..65e0d98a7fd 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php @@ -68,6 +68,9 @@ abstract class ReadOnlyStream implements StreamWrapperInterface { * 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 @@ abstract class ReadOnlyStream implements StreamWrapperInterface { 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 3b513430b0d..ce9b0e0e619 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -365,11 +365,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