From 2c068f3683f8003f27fcc971ffe16fa07b563947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Fri, 13 Mar 2026 13:10:25 +0100 Subject: [PATCH] fix: Remove static vars from applications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Service/BackupCodeStorage.php | 4 ++-- apps/workflowengine/lib/Command/Index.php | 7 ++++--- apps/workflowengine/lib/Manager.php | 15 ++++++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php b/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php index 7dd6b3949e2..24621ba2ee2 100644 --- a/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php +++ b/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php @@ -17,7 +17,7 @@ use OCP\Security\IHasher; use OCP\Security\ISecureRandom; class BackupCodeStorage { - private static $CODE_LENGTH = 16; + private const CODE_LENGTH = 16; public function __construct( private BackupCodeMapper $mapper, @@ -40,7 +40,7 @@ class BackupCodeStorage { $uid = $user->getUID(); foreach (range(1, min([$number, 20])) as $i) { - $code = $this->random->generate(self::$CODE_LENGTH, ISecureRandom::CHAR_HUMAN_READABLE); + $code = $this->random->generate(self::CODE_LENGTH, ISecureRandom::CHAR_HUMAN_READABLE); $dbCode = new BackupCode(); $dbCode->setUserId($uid); diff --git a/apps/workflowengine/lib/Command/Index.php b/apps/workflowengine/lib/Command/Index.php index 1fb8cb416b0..c38d19a087e 100644 --- a/apps/workflowengine/lib/Command/Index.php +++ b/apps/workflowengine/lib/Command/Index.php @@ -6,6 +6,7 @@ declare(strict_types=1); * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OCA\WorkflowEngine\Command; use OCA\WorkflowEngine\Helper\ScopeContext; @@ -43,11 +44,11 @@ class Index extends Command { } protected function mappedScope(string $scope): int { - static $scopes = [ + return match($scope) { 'admin' => IManager::SCOPE_ADMIN, 'user' => IManager::SCOPE_USER, - ]; - return $scopes[$scope] ?? -1; + default => -1, + }; } protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index e426f96ac4a..a0f479c4370 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -65,6 +65,9 @@ class Manager implements IManager { /** @var CappedMemoryCache */ protected CappedMemoryCache $operationsByScope; + /** @var array, ScopeContext[]> $scopesByOperation */ + private array $scopesByOperation = []; + public function __construct( protected readonly IDBConnection $connection, protected readonly ContainerInterface $container, @@ -128,10 +131,8 @@ class Manager implements IManager { * @return ScopeContext[] */ public function getAllConfiguredScopesForOperation(string $operationClass): array { - /** @var array, ScopeContext[]> $scopesByOperation */ - static $scopesByOperation = []; - if (isset($scopesByOperation[$operationClass])) { - return $scopesByOperation[$operationClass]; + if (isset($this->scopesByOperation[$operationClass])) { + return $this->scopesByOperation[$operationClass]; } try { @@ -152,7 +153,7 @@ class Manager implements IManager { $query->setParameters(['operationClass' => $operationClass]); $result = $query->executeQuery(); - $scopesByOperation[$operationClass] = []; + $this->scopesByOperation[$operationClass] = []; while ($row = $result->fetchAssociative()) { $scope = new ScopeContext($row['type'], $row['value']); @@ -160,10 +161,10 @@ class Manager implements IManager { continue; } - $scopesByOperation[$operationClass][$scope->getHash()] = $scope; + $this->scopesByOperation[$operationClass][$scope->getHash()] = $scope; } - return $scopesByOperation[$operationClass]; + return $this->scopesByOperation[$operationClass]; } public function getAllOperations(ScopeContext $scopeContext): array {