Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
];

/** @var array parameters to index */
public static array $indexParameters = [
private const INDEXED_PARAMETERS = [
'ATTENDEE' => ['CN'],
'ORGANIZER' => ['CN'],
];
Expand Down Expand Up @@ -3382,9 +3382,9 @@ public function updateProperties($calendarId, $objectUri, $calendarData, $calend
$query->executeStatement();
}

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

foreach ($parameters as $key => $value) {
if (in_array($key, $indexedParametersForProperty)) {
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
private string $dbCardsPropertiesTable = 'cards_properties';

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

foreach ($vCard->children() as $property) {
if (!in_array($property->name, self::$indexProperties)) {
if (!in_array($property->name, self::INDEXED_PROPERTIES)) {
continue;
}
$preferred = 0;
Expand Down
6 changes: 3 additions & 3 deletions apps/dav/lib/Search/ContactsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
use Sabre\VObject\Reader;

class ContactsSearchProvider implements IFilteringProvider {
private static array $searchPropertiesRestricted = [
private const SEARCH_PROPERTIES_RESTRICTED = [
'N',
'FN',
'NICKNAME',
'EMAIL',
];

private static array $searchProperties = [
private const SEARCH_PROPERTIES = [
'N',
'FN',
'NICKNAME',
Expand Down Expand Up @@ -87,7 +87,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$searchResults = $this->backend->searchPrincipalUri(
$principalUri,
$query->getFilter('term')?->get() ?? '',
$query->getFilter('title-only')?->get() ? self::$searchPropertiesRestricted : self::$searchProperties,
$query->getFilter('title-only')?->get() ? self::SEARCH_PROPERTIES_RESTRICTED : self::SEARCH_PROPERTIES,
[
'limit' => $query->getLimit(),
'offset' => $query->getCursor(),
Expand Down
18 changes: 9 additions & 9 deletions apps/dav/lib/Search/EventsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* @var string[]
*/
private static $searchProperties = [
private const SEARCH_PROPERTIES = [
'SUMMARY',
'LOCATION',
'DESCRIPTION',
Expand All @@ -44,15 +44,15 @@
/**
* @var string[]
*/
private static $searchParameters = [
private const SEARCH_PARAMETERS = [

Check failure on line 47 in apps/dav/lib/Search/EventsSearchProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidConstantAssignmentValue

apps/dav/lib/Search/EventsSearchProvider.php:47:16: InvalidConstantAssignmentValue: OCA\DAV\Search\EventsSearchProvider::SEARCH_PARAMETERS with declared type array<array-key, string> cannot be assigned type array{ATTENDEE: list{'CN'}, ORGANIZER: list{'CN'}} (see https://psalm.dev/304)
'ATTENDEE' => ['CN'],
'ORGANIZER' => ['CN'],
];

/**
* @var string
*/
private static $componentType = 'VEVENT';
private const COMPONENT_TYPE = 'VEVENT';

/**
* @inheritDoc
Expand Down Expand Up @@ -102,9 +102,9 @@
$searchResults = $this->backend->searchPrincipalUri(
$principalUri,
$term,
[self::$componentType],
self::$searchProperties,
self::$searchParameters,
[self::COMPONENT_TYPE],
self::SEARCH_PROPERTIES,
self::SEARCH_PARAMETERS,
[
'limit' => $query->getLimit(),
'offset' => $query->getCursor(),
Expand All @@ -122,9 +122,9 @@
$attendeeSearchResults = $this->backend->searchPrincipalUri(
$principalUri,
$personDisplayName,
[self::$componentType],
[self::COMPONENT_TYPE],
['ATTENDEE'],
self::$searchParameters,
self::SEARCH_PARAMETERS,
[
'limit' => $query->getLimit(),
'offset' => $query->getCursor(),
Expand All @@ -148,7 +148,7 @@
}
}
$formattedResults = \array_map(function (array $eventRow) use ($calendarsById, $subscriptionsById): SearchResultEntry {
$component = $this->getPrimaryComponent($eventRow['calendardata'], self::$componentType);
$component = $this->getPrimaryComponent($eventRow['calendardata'], self::COMPONENT_TYPE);
$title = (string)($component->SUMMARY ?? $this->l10n->t('Untitled event'));

if ($eventRow['calendartype'] === CalDavBackend::CALENDAR_TYPE_CALENDAR) {
Expand Down
14 changes: 7 additions & 7 deletions apps/dav/lib/Search/TasksSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TasksSearchProvider extends ACalendarSearchProvider {
/**
* @var string[]
*/
private static $searchProperties = [
private const SEARCH_PROPERTIES = [
'SUMMARY',
'DESCRIPTION',
'CATEGORIES',
Expand All @@ -33,12 +33,12 @@ class TasksSearchProvider extends ACalendarSearchProvider {
/**
* @var string[]
*/
private static $searchParameters = [];
private const SEARCH_PARAMETERS = [];

/**
* @var string
*/
private static $componentType = 'VTODO';
private const COMPONENT_TYPE = 'VTODO';

/**
* @inheritDoc
Expand Down Expand Up @@ -83,9 +83,9 @@ public function search(
$searchResults = $this->backend->searchPrincipalUri(
$principalUri,
$query->getFilter('term')?->get() ?? '',
[self::$componentType],
self::$searchProperties,
self::$searchParameters,
[self::COMPONENT_TYPE],
self::SEARCH_PROPERTIES,
self::SEARCH_PARAMETERS,
[
'limit' => $query->getLimit(),
'offset' => $query->getCursor(),
Expand All @@ -94,7 +94,7 @@ public function search(
]
);
$formattedResults = \array_map(function (array $taskRow) use ($calendarsById, $subscriptionsById):SearchResultEntry {
$component = $this->getPrimaryComponent($taskRow['calendardata'], self::$componentType);
$component = $this->getPrimaryComponent($taskRow['calendardata'], self::COMPONENT_TYPE);
$title = (string)($component->SUMMARY ?? $this->l10n->t('Untitled task'));

if ($taskRow['calendartype'] === CalDavBackend::CALENDAR_TYPE_CALENDAR) {
Expand Down
9 changes: 4 additions & 5 deletions apps/encryption/lib/Services/PassphraseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
use Psr\Log\LoggerInterface;

class PassphraseService {

/** @var array<string, bool> */
private static array $passwordResetUsers = [];
private array $passwordResetUsers = [];

public function __construct(
private Util $util,
Expand All @@ -39,9 +38,9 @@ public function __construct(

public function setProcessingReset(string $uid, bool $processing = true): void {
if ($processing) {
self::$passwordResetUsers[$uid] = true;
$this->passwordResetUsers[$uid] = true;
} else {
unset(self::$passwordResetUsers[$uid]);
unset($this->passwordResetUsers[$uid]);
}
}

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

Expand Down
34 changes: 0 additions & 34 deletions apps/files/lib/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,9 @@
*/
namespace OCA\Files;

use OC\NavigationManager;
use OCA\Files\Service\ChunkedUploadConfig;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Server;
use Psr\Log\LoggerInterface;

class App {
private static ?INavigationManager $navigationManager = null;

/**
* Returns the app's navigation manager
*/
public static function getNavigationManager(): INavigationManager {
// TODO: move this into a service in the Application class
if (self::$navigationManager === null) {
self::$navigationManager = new NavigationManager(
Server::get(IAppManager::class),
Server::get(IUrlGenerator::class),
Server::get(IFactory::class),
Server::get(IUserSession::class),
Server::get(IGroupManager::class),
Server::get(IConfig::class),
Server::get(LoggerInterface::class),
Server::get(IEventDispatcher::class),
);
self::$navigationManager->clear(false);
}
return self::$navigationManager;
}

public static function extendJsConfig($settings): void {
$appConfig = json_decode($settings['array']['oc_appconfig'], true);

Expand Down
10 changes: 5 additions & 5 deletions apps/files_external/lib/Service/BackendService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class BackendService {
/** @var callable[] */
private $configHandlerLoaders = [];

private $configHandlers = [];
private array $configHandlers = [];
private bool $eventSent = false;

public function __construct(
protected readonly IAppConfig $appConfig,
Expand All @@ -71,14 +72,13 @@ public function registerBackendProvider(IBackendProvider $provider) {
$this->backendProviders[] = $provider;
}

private function callForRegistrations() {
static $eventSent = false;
if (!$eventSent) {
private function callForRegistrations(): void {
if (!$this->eventSent) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails in tests because the listener gets the singleton from container and tries to re-register the backend.
It can only happen if code creates BackendService objects.

Not sure how to best fix it.
Ideally we should move to a typed event with a pointer to the backend service. But that cannot be done right away.

Maybe we should get the singleton from container and check eventSent on it?

Server::get(IEventDispatcher::class)->dispatch(
'OCA\\Files_External::loadAdditionalBackends',
new GenericEvent()
);
$eventSent = true;
$this->eventSent = true;
}
}

Expand Down
6 changes: 3 additions & 3 deletions apps/files_trashbin/lib/Command/RestoreAllFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RestoreAllFiles extends Base {
private const SCOPE_USER = 1;
private const SCOPE_GROUPFOLDERS = 2;

private static array $SCOPE_MAP = [
private const SCOPE_MAP = [
'user' => self::SCOPE_USER,
'groupfolders' => self::SCOPE_GROUPFOLDERS,
'all' => self::SCOPE_ALL
Expand Down Expand Up @@ -218,8 +218,8 @@ protected function parseArgs(InputInterface $input): array {
}

protected function parseScope(string $scope): int {
if (isset(self::$SCOPE_MAP[$scope])) {
return self::$SCOPE_MAP[$scope];
if (isset(self::SCOPE_MAP[$scope])) {
return self::SCOPE_MAP[$scope];
}

throw new InvalidOptionException("Invalid scope '$scope'");
Expand Down
14 changes: 7 additions & 7 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
public const DELETE_TRIGGER_QUOTA_EXCEEDED = 2;

// files for which we can remove the versions after the delete operation was successful
private static $deletedFiles = [];

Check failure on line 59 in apps/files_versions/lib/Storage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ImpureStaticProperty

apps/files_versions/lib/Storage.php:59:2: ImpureStaticProperty: Static property should not be used as they do not follow requests lifecycle (see https://psalm.dev/221)

private static $sourcePathAndUser = [];

Check failure on line 61 in apps/files_versions/lib/Storage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ImpureStaticProperty

apps/files_versions/lib/Storage.php:61:2: ImpureStaticProperty: Static property should not be used as they do not follow requests lifecycle (see https://psalm.dev/221)

private static $max_versions_per_interval = [
private const MAX_VERSIONS_PER_INTERVAL = [
//first 10sec, one version every 2sec
1 => ['intervalEndsAfter' => 10, 'step' => 2],
//next minute, one version every 10sec
Expand All @@ -76,7 +76,7 @@
];

/** @var Application */
private static $application;

Check failure on line 79 in apps/files_versions/lib/Storage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ImpureStaticProperty

apps/files_versions/lib/Storage.php:79:2: ImpureStaticProperty: Static property should not be used as they do not follow requests lifecycle (see https://psalm.dev/221)

/**
* get the UID of the owner of the file and the path to the file relative to
Expand Down Expand Up @@ -763,11 +763,11 @@
$toDelete = []; // versions we want to delete

$interval = 1;
$step = Storage::$max_versions_per_interval[$interval]['step'];
if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] === -1) {
$step = Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['step'];
if (Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1) {

Check failure on line 767 in apps/files_versions/lib/Storage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TypeDoesNotContainType

apps/files_versions/lib/Storage.php:767:7: TypeDoesNotContainType: Type 10 for OCA\Files_Versions\Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] is never =int(-1) (see https://psalm.dev/056)

Check failure on line 767 in apps/files_versions/lib/Storage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TypeDoesNotContainType

apps/files_versions/lib/Storage.php:767:7: TypeDoesNotContainType: -1 cannot be identical to 10 (see https://psalm.dev/056)
$nextInterval = -1;
} else {
$nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'];
$nextInterval = $time - Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'];
}

$firstVersion = reset($versions);
Expand Down Expand Up @@ -797,12 +797,12 @@
$newInterval = false; // version checked so we can move to the next one
} else { // time to move on to the next interval
$interval++;
$step = Storage::$max_versions_per_interval[$interval]['step'];
$step = Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['step'];

Check failure on line 800 in apps/files_versions/lib/Storage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArrayOffset

apps/files_versions/lib/Storage.php:800:14: InvalidArrayOffset: Cannot access value on variable OCA\Files_Versions\Storage::MAX_VERSIONS_PER_INTERVAL using a int<2, max> offset, expecting 1|2|3|4|5|6 (see https://psalm.dev/115)
$nextVersion = $prevTimestamp - $step;
if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] === -1) {
if (Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1) {
$nextInterval = -1;
} else {
$nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'];
$nextInterval = $time - Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'];
}
$newInterval = true; // we changed the interval -> check same version with new interval
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use OCP\Security\ISecureRandom;

class BackupCodeStorage {
private static $CODE_LENGTH = 16;
private const CODE_LENGTH = 16;

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

$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);
Expand Down
9 changes: 2 additions & 7 deletions apps/user_ldap/lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,9 @@ protected function getSystemValue(string $varName): string {
}

protected function getValue(string $varName): string {
static $defaults;
if (is_null($defaults)) {
$defaults = $this->getDefaults();
}
return Server::get(IConfig::class)->getAppValue('user_ldap',
$this->configPrefix . $varName,
$defaults[$varName]);
$this->getDefaults()[$varName]);
}

/**
Expand Down Expand Up @@ -571,7 +567,7 @@ public function getDefaults(): array {
*/
public function getConfigTranslationArray(): array {
//TODO: merge them into one representation
static $array = [
return [
'ldap_host' => 'ldapHost',
'ldap_port' => 'ldapPort',
'ldap_backup_host' => 'ldapBackupHost',
Expand Down Expand Up @@ -644,7 +640,6 @@ public function getConfigTranslationArray(): array {
'ldap_attr_anniversarydate' => 'ldapAttributeAnniversaryDate',
'ldap_attr_pronouns' => 'ldapAttributePronouns',
];
return $array;
}

/**
Expand Down
Loading
Loading