From f8111a7a7ee2eaab72a54d9d7a5d65f2f83f9d7a Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 26 Jun 2023 20:00:51 +0100 Subject: [PATCH] Replace inline static with class static (#18490) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kamil Tekiela Co-authored-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Config.php | 13 ++++++------- psalm-baseline.xml | 5 ++--- test/classes/ConfigTest.php | 2 ++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/classes/Config.php b/libraries/classes/Config.php index 9b43b680a4..26d75a51f8 100644 --- a/libraries/classes/Config.php +++ b/libraries/classes/Config.php @@ -93,6 +93,9 @@ class Config /** @var int<0, max> */ public int $server = 0; + /** @var array $tempDir */ + private static array $tempDir = []; + public function __construct() { $this->config = new Settings([]); @@ -1001,15 +1004,11 @@ class Config * Returns temporary dir path * * @param string $name Directory name - * - * @staticvar array $temp_dir */ public function getTempDir(string $name): string|null { - static $tempDir = []; - - if (isset($tempDir[$name]) && ! defined('TESTSUITE')) { - return $tempDir[$name]; + if (isset(self::$tempDir[$name])) { + return self::$tempDir[$name]; } $path = $this->get('TempDir'); @@ -1026,7 +1025,7 @@ class Config } } - $tempDir[$name] = $path; + self::$tempDir[$name] = $path; return $path; } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d94ff2d5cc..162813db4d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -263,7 +263,6 @@ - $tempDir[$name] @@ -280,10 +279,10 @@ $value - string|null + string - $tempDir[$name] + $cookiePath $defaultValue diff --git a/test/classes/ConfigTest.php b/test/classes/ConfigTest.php index 649aeccc63..594bc50462 100644 --- a/test/classes/ConfigTest.php +++ b/test/classes/ConfigTest.php @@ -12,6 +12,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\Attributes\Group; +use ReflectionProperty; use function define; use function defined; @@ -672,6 +673,7 @@ PHP; $this->assertDirectoryExists($dir); $this->assertDirectoryIsWritable($dir); + (new ReflectionProperty(Config::class, 'tempDir'))->setValue([]); $this->object->set('TempDir', $dir . DIRECTORY_SEPARATOR); // Check no double slash is here $this->assertEquals(