Skip to content

Commit f8111a7

Browse files
Replace inline static with class static (#18490)
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> Co-authored-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 62a2b7f commit f8111a7

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎libraries/classes/Config.php‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class Config
9393
/** @var int<0, max> */
9494
public int $server = 0;
9595

96+
/** @var array<string,string|null> $tempDir */
97+
private static array $tempDir = [];
98+
9699
public function __construct()
97100
{
98101
$this->config = new Settings([]);
@@ -1001,15 +1004,11 @@ public static function renderHeader(): string
10011004
* Returns temporary dir path
10021005
*
10031006
* @param string $name Directory name
1004-
*
1005-
* @staticvar array<string,string|null> $temp_dir
10061007
*/
10071008
public function getTempDir(string $name): string|null
10081009
{
1009-
static $tempDir = [];
1010-
1011-
if (isset($tempDir[$name]) && ! defined('TESTSUITE')) {
1012-
return $tempDir[$name];
1010+
if (isset(self::$tempDir[$name])) {
1011+
return self::$tempDir[$name];
10131012
}
10141013

10151014
$path = $this->get('TempDir');
@@ -1026,7 +1025,7 @@ public function getTempDir(string $name): string|null
10261025
}
10271026
}
10281027

1029-
$tempDir[$name] = $path;
1028+
self::$tempDir[$name] = $path;
10301029

10311030
return $path;
10321031
}

‎psalm-baseline.xml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@
263263
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs']]]></code>
264264
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs_mtime']]]></code>
265265
<code><![CDATA[$_SESSION['cache'][$cacheKey]['userprefs_type']]]></code>
266-
<code>$tempDir[$name]</code>
267266
</MixedArrayAssignment>
268267
<MixedAssignment>
269268
<code><![CDATA[$GLOBALS['cfg']['LoginCookieValidity']]]></code>
@@ -280,10 +279,10 @@
280279
<code>$value</code>
281280
</MixedAssignment>
282281
<MixedInferredReturnType>
283-
<code>string|null</code>
282+
<code>string</code>
284283
</MixedInferredReturnType>
285284
<MixedReturnStatement>
286-
<code>$tempDir[$name]</code>
285+
<code>$cookiePath</code>
287286
</MixedReturnStatement>
288287
<PossiblyInvalidArgument>
289288
<code>$defaultValue</code>

‎test/classes/ConfigTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPUnit\Framework\Attributes\DataProvider;
1313
use PHPUnit\Framework\Attributes\Depends;
1414
use PHPUnit\Framework\Attributes\Group;
15+
use ReflectionProperty;
1516

1617
use function define;
1718
use function defined;
@@ -672,6 +673,7 @@ public function testGetTempDir(): void
672673
$this->assertDirectoryExists($dir);
673674
$this->assertDirectoryIsWritable($dir);
674675

676+
(new ReflectionProperty(Config::class, 'tempDir'))->setValue([]);
675677
$this->object->set('TempDir', $dir . DIRECTORY_SEPARATOR);
676678
// Check no double slash is here
677679
$this->assertEquals(

0 commit comments

Comments
 (0)