Skip to content

Commit c88a1d3

Browse files
committed
fix: Remove static vars usage in user_ldap
There are still some left, harder to remove. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 9b84a0e commit c88a1d3

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

apps/user_ldap/lib/Configuration.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,9 @@ protected function getSystemValue(string $varName): string {
444444
}
445445

446446
protected function getValue(string $varName): string {
447-
static $defaults;
448-
if (is_null($defaults)) {
449-
$defaults = $this->getDefaults();
450-
}
451447
return Server::get(IConfig::class)->getAppValue('user_ldap',
452448
$this->configPrefix . $varName,
453-
$defaults[$varName]);
449+
$this->getDefaults()[$varName]);
454450
}
455451

456452
/**

apps/user_ldap/lib/Mapping/UserMapping.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
68
* SPDX-License-Identifier: AGPL-3.0-only
79
*/
10+
811
namespace OCA\User_LDAP\Mapping;
912

1013
use OCP\HintException;
1114
use OCP\IAppConfig;
1215
use OCP\ICacheFactory;
1316
use OCP\IDBConnection;
1417
use OCP\IRequest;
15-
use OCP\Server;
1618
use OCP\Support\Subscription\IAssertion;
1719

1820
/**
@@ -30,6 +32,7 @@ public function __construct(
3032
IAppConfig $config,
3133
bool $isCLI,
3234
private IAssertion $assertion,
35+
private IRequest $request,
3336
) {
3437
parent::__construct($dbc, $cacheFactory, $config, $isCLI);
3538
}
@@ -41,13 +44,7 @@ public function map($fdn, $name, $uuid): bool {
4144
try {
4245
$this->assertion->createUserIsLegit();
4346
} catch (HintException $e) {
44-
static $isProvisioningApi = null;
45-
46-
if ($isProvisioningApi === null) {
47-
$request = Server::get(IRequest::class);
48-
$isProvisioningApi = \preg_match(self::PROV_API_REGEX, $request->getRequestUri()) === 1;
49-
}
50-
if ($isProvisioningApi) {
47+
if (\preg_match(self::PROV_API_REGEX, $this->request->getRequestUri()) === 1) {
5148
// only throw when prov API is being used, since functionality
5249
// should not break for end users (e.g. when sharing).
5350
// On direct API usage, e.g. on users page, this is desired.

apps/user_ldap/tests/Mapping/UserMappingTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCP\IAppConfig;
1313
use OCP\ICacheFactory;
1414
use OCP\IDBConnection;
15+
use OCP\IRequest;
1516
use OCP\Support\Subscription\IAssertion;
1617

1718
/**
@@ -23,6 +24,6 @@
2324
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
2425
class UserMappingTest extends AbstractMappingTestCase {
2526
public function getMapper(IDBConnection $dbMock, ICacheFactory $cacheFactory, IAppConfig $appConfig): UserMapping {
26-
return new UserMapping($dbMock, $cacheFactory, $appConfig, true, $this->createMock(IAssertion::class));
27+
return new UserMapping($dbMock, $cacheFactory, $appConfig, true, $this->createMock(IAssertion::class), $this->createMock(IRequest::class));
2728
}
2829
}

0 commit comments

Comments
 (0)