Skip to content

Commit 5a7d38b

Browse files
authored
Merge pull request #59159 from nextcloud/fix/remove-static-vars-batch
Remove static vars, first batch
2 parents e4c2a1d + e367c5a commit 5a7d38b

26 files changed

Lines changed: 97 additions & 166 deletions

File tree

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
190190
];
191191

192192
/** @var array parameters to index */
193-
public static array $indexParameters = [
193+
private const INDEXED_PARAMETERS = [
194194
'ATTENDEE' => ['CN'],
195195
'ORGANIZER' => ['CN'],
196196
];
@@ -3386,9 +3386,9 @@ public function updateProperties($calendarId, $objectUri, $calendarData, $calend
33863386
$query->executeStatement();
33873387
}
33883388

3389-
if (array_key_exists($property->name, self::$indexParameters)) {
3389+
if (array_key_exists($property->name, self::INDEXED_PARAMETERS)) {
33903390
$parameters = $property->parameters();
3391-
$indexedParametersForProperty = self::$indexParameters[$property->name];
3391+
$indexedParametersForProperty = self::INDEXED_PARAMETERS[$property->name];
33923392

33933393
foreach ($parameters as $key => $value) {
33943394
if (in_array($key, $indexedParametersForProperty)) {

apps/dav/lib/CardDAV/CardDavBackend.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
4242
private string $dbCardsPropertiesTable = 'cards_properties';
4343

4444
/** @var array properties to index */
45-
public static array $indexProperties = [
45+
private const INDEXED_PROPERTIES = [
4646
'BDAY', 'UID', 'N', 'FN', 'TITLE', 'ROLE', 'NOTE', 'NICKNAME',
4747
'ORG', 'CATEGORIES', 'EMAIL', 'TEL', 'IMPP', 'ADR', 'URL', 'GEO',
4848
'CLOUD', 'X-SOCIALPROFILE'];
@@ -1384,7 +1384,7 @@ protected function updateProperties($addressBookId, $cardUri, $vCardSerialized)
13841384
);
13851385

13861386
foreach ($vCard->children() as $property) {
1387-
if (!in_array($property->name, self::$indexProperties)) {
1387+
if (!in_array($property->name, self::INDEXED_PROPERTIES)) {
13881388
continue;
13891389
}
13901390
$preferred = 0;

apps/dav/lib/Search/ContactsSearchProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
use Sabre\VObject\Reader;
2424

2525
class ContactsSearchProvider implements IFilteringProvider {
26-
private static array $searchPropertiesRestricted = [
26+
private const SEARCH_PROPERTIES_RESTRICTED = [
2727
'N',
2828
'FN',
2929
'NICKNAME',
3030
'EMAIL',
3131
];
3232

33-
private static array $searchProperties = [
33+
private const SEARCH_PROPERTIES = [
3434
'N',
3535
'FN',
3636
'NICKNAME',
@@ -87,7 +87,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
8787
$searchResults = $this->backend->searchPrincipalUri(
8888
$principalUri,
8989
$query->getFilter('term')?->get() ?? '',
90-
$query->getFilter('title-only')?->get() ? self::$searchPropertiesRestricted : self::$searchProperties,
90+
$query->getFilter('title-only')?->get() ? self::SEARCH_PROPERTIES_RESTRICTED : self::SEARCH_PROPERTIES,
9191
[
9292
'limit' => $query->getLimit(),
9393
'offset' => $query->getCursor(),

apps/dav/lib/Search/EventsSearchProvider.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class EventsSearchProvider extends ACalendarSearchProvider implements IFiltering
3232
/**
3333
* @var string[]
3434
*/
35-
private static $searchProperties = [
35+
private const SEARCH_PROPERTIES = [
3636
'SUMMARY',
3737
'LOCATION',
3838
'DESCRIPTION',
@@ -42,17 +42,17 @@ class EventsSearchProvider extends ACalendarSearchProvider implements IFiltering
4242
];
4343

4444
/**
45-
* @var string[]
45+
* @var array<string, string[]>
4646
*/
47-
private static $searchParameters = [
47+
private const SEARCH_PARAMETERS = [
4848
'ATTENDEE' => ['CN'],
4949
'ORGANIZER' => ['CN'],
5050
];
5151

5252
/**
5353
* @var string
5454
*/
55-
private static $componentType = 'VEVENT';
55+
private const COMPONENT_TYPE = 'VEVENT';
5656

5757
/**
5858
* @inheritDoc
@@ -102,9 +102,9 @@ public function search(
102102
$searchResults = $this->backend->searchPrincipalUri(
103103
$principalUri,
104104
$term,
105-
[self::$componentType],
106-
self::$searchProperties,
107-
self::$searchParameters,
105+
[self::COMPONENT_TYPE],
106+
self::SEARCH_PROPERTIES,
107+
self::SEARCH_PARAMETERS,
108108
[
109109
'limit' => $query->getLimit(),
110110
'offset' => $query->getCursor(),
@@ -122,9 +122,9 @@ public function search(
122122
$attendeeSearchResults = $this->backend->searchPrincipalUri(
123123
$principalUri,
124124
$personDisplayName,
125-
[self::$componentType],
125+
[self::COMPONENT_TYPE],
126126
['ATTENDEE'],
127-
self::$searchParameters,
127+
self::SEARCH_PARAMETERS,
128128
[
129129
'limit' => $query->getLimit(),
130130
'offset' => $query->getCursor(),
@@ -148,7 +148,7 @@ public function search(
148148
}
149149
}
150150
$formattedResults = \array_map(function (array $eventRow) use ($calendarsById, $subscriptionsById): SearchResultEntry {
151-
$component = $this->getPrimaryComponent($eventRow['calendardata'], self::$componentType);
151+
$component = $this->getPrimaryComponent($eventRow['calendardata'], self::COMPONENT_TYPE);
152152
$title = (string)($component->SUMMARY ?? $this->l10n->t('Untitled event'));
153153

154154
if ($eventRow['calendartype'] === CalDavBackend::CALENDAR_TYPE_CALENDAR) {

apps/dav/lib/Search/TasksSearchProvider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TasksSearchProvider extends ACalendarSearchProvider {
2424
/**
2525
* @var string[]
2626
*/
27-
private static $searchProperties = [
27+
private const SEARCH_PROPERTIES = [
2828
'SUMMARY',
2929
'DESCRIPTION',
3030
'CATEGORIES',
@@ -33,12 +33,12 @@ class TasksSearchProvider extends ACalendarSearchProvider {
3333
/**
3434
* @var string[]
3535
*/
36-
private static $searchParameters = [];
36+
private const SEARCH_PARAMETERS = [];
3737

3838
/**
3939
* @var string
4040
*/
41-
private static $componentType = 'VTODO';
41+
private const COMPONENT_TYPE = 'VTODO';
4242

4343
/**
4444
* @inheritDoc
@@ -83,9 +83,9 @@ public function search(
8383
$searchResults = $this->backend->searchPrincipalUri(
8484
$principalUri,
8585
$query->getFilter('term')?->get() ?? '',
86-
[self::$componentType],
87-
self::$searchProperties,
88-
self::$searchParameters,
86+
[self::COMPONENT_TYPE],
87+
self::SEARCH_PROPERTIES,
88+
self::SEARCH_PARAMETERS,
8989
[
9090
'limit' => $query->getLimit(),
9191
'offset' => $query->getCursor(),
@@ -94,7 +94,7 @@ public function search(
9494
]
9595
);
9696
$formattedResults = \array_map(function (array $taskRow) use ($calendarsById, $subscriptionsById):SearchResultEntry {
97-
$component = $this->getPrimaryComponent($taskRow['calendardata'], self::$componentType);
97+
$component = $this->getPrimaryComponent($taskRow['calendardata'], self::COMPONENT_TYPE);
9898
$title = (string)($component->SUMMARY ?? $this->l10n->t('Untitled task'));
9999

100100
if ($taskRow['calendartype'] === CalDavBackend::CALENDAR_TYPE_CALENDAR) {

apps/encryption/lib/Services/PassphraseService.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
use Psr\Log\LoggerInterface;
2222

2323
class PassphraseService {
24-
2524
/** @var array<string, bool> */
26-
private static array $passwordResetUsers = [];
25+
private array $passwordResetUsers = [];
2726

2827
public function __construct(
2928
private Util $util,
@@ -39,9 +38,9 @@ public function __construct(
3938

4039
public function setProcessingReset(string $uid, bool $processing = true): void {
4140
if ($processing) {
42-
self::$passwordResetUsers[$uid] = true;
41+
$this->passwordResetUsers[$uid] = true;
4342
} else {
44-
unset(self::$passwordResetUsers[$uid]);
43+
unset($this->passwordResetUsers[$uid]);
4544
}
4645
}
4746

@@ -51,7 +50,7 @@ public function setProcessingReset(string $uid, bool $processing = true): void {
5150
public function setPassphraseForUser(string $userId, string $password, ?string $recoveryPassword = null): bool {
5251
// if we are in the process to resetting a user password, we have nothing
5352
// to do here
54-
if (isset(self::$passwordResetUsers[$userId])) {
53+
if (isset($this->passwordResetUsers[$userId])) {
5554
return true;
5655
}
5756

apps/files/lib/App.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,9 @@
77
*/
88
namespace OCA\Files;
99

10-
use OC\NavigationManager;
1110
use OCA\Files\Service\ChunkedUploadConfig;
12-
use OCP\App\IAppManager;
13-
use OCP\EventDispatcher\IEventDispatcher;
14-
use OCP\IConfig;
15-
use OCP\IGroupManager;
16-
use OCP\INavigationManager;
17-
use OCP\IURLGenerator;
18-
use OCP\IUserSession;
19-
use OCP\L10N\IFactory;
20-
use OCP\Server;
21-
use Psr\Log\LoggerInterface;
2211

2312
class App {
24-
private static ?INavigationManager $navigationManager = null;
25-
26-
/**
27-
* Returns the app's navigation manager
28-
*/
29-
public static function getNavigationManager(): INavigationManager {
30-
// TODO: move this into a service in the Application class
31-
if (self::$navigationManager === null) {
32-
self::$navigationManager = new NavigationManager(
33-
Server::get(IAppManager::class),
34-
Server::get(IUrlGenerator::class),
35-
Server::get(IFactory::class),
36-
Server::get(IUserSession::class),
37-
Server::get(IGroupManager::class),
38-
Server::get(IConfig::class),
39-
Server::get(LoggerInterface::class),
40-
Server::get(IEventDispatcher::class),
41-
);
42-
self::$navigationManager->clear(false);
43-
}
44-
return self::$navigationManager;
45-
}
46-
4713
public static function extendJsConfig($settings): void {
4814
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
4915

apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use OCP\Security\ISecureRandom;
1818

1919
class BackupCodeStorage {
20-
private static $CODE_LENGTH = 16;
20+
private const CODE_LENGTH = 16;
2121

2222
public function __construct(
2323
private BackupCodeMapper $mapper,
@@ -40,7 +40,7 @@ public function createCodes(IUser $user, int $number = 10): array {
4040

4141
$uid = $user->getUID();
4242
foreach (range(1, min([$number, 20])) as $i) {
43-
$code = $this->random->generate(self::$CODE_LENGTH, ISecureRandom::CHAR_HUMAN_READABLE);
43+
$code = $this->random->generate(self::CODE_LENGTH, ISecureRandom::CHAR_HUMAN_READABLE);
4444

4545
$dbCode = new BackupCode();
4646
$dbCode->setUserId($uid);

apps/user_ldap/lib/Configuration.php

Lines changed: 2 additions & 7 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
/**
@@ -571,7 +567,7 @@ public function getDefaults(): array {
571567
*/
572568
public function getConfigTranslationArray(): array {
573569
//TODO: merge them into one representation
574-
static $array = [
570+
return [
575571
'ldap_host' => 'ldapHost',
576572
'ldap_port' => 'ldapPort',
577573
'ldap_backup_host' => 'ldapBackupHost',
@@ -644,7 +640,6 @@ public function getConfigTranslationArray(): array {
644640
'ldap_attr_anniversarydate' => 'ldapAttributeAnniversaryDate',
645641
'ldap_attr_pronouns' => 'ldapAttributePronouns',
646642
];
647-
return $array;
648643
}
649644

650645
/**

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.

0 commit comments

Comments
 (0)