fix(lexicon): syntax

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/49848/head
Maxence Lange 9 months ago
parent bd4a154d64
commit 28acc002a2
  1. 9
      lib/private/Config/Lexicon/CoreConfigLexicon.php
  2. 41
      lib/private/Config/UserConfig.php
  3. 2
      lib/unstable/Config/Lexicon/ConfigLexiconEntry.php
  4. 5
      tests/Core/Command/Config/App/GetConfigTest.php

@ -3,7 +3,7 @@
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Config\Lexicon;
@ -17,11 +17,6 @@ use NCU\Config\ValueType;
* ConfigLexicon for 'core' app/user configs
*/
class CoreConfigLexicon implements IConfigLexicon {
/**
* @inheritDoc
* @return ConfigLexiconStrictness
* @since 31.0.0
*/
public function getStrictness(): ConfigLexiconStrictness {
return ConfigLexiconStrictness::IGNORE;
}
@ -29,7 +24,6 @@ class CoreConfigLexicon implements IConfigLexicon {
/**
* @inheritDoc
* @return ConfigLexiconEntry[]
* @since 31.0.0
*/
public function getAppConfigs(): array {
return [
@ -40,7 +34,6 @@ class CoreConfigLexicon implements IConfigLexicon {
/**
* @inheritDoc
* @return ConfigLexiconEntry[]
* @since 31.0.0
*/
public function getUserConfigs(): array {
return [

@ -229,7 +229,8 @@ class UserConfig implements IUserConfig {
// there is a huge probability the non-lazy config are already loaded
// meaning that we can start by only checking if a current non-lazy key exists
if ($this->hasKey($userId, $app, $key, false)) {
return false; // meaning key is not lazy.
// meaning key is not lazy.
return false;
}
// as key is not found as non-lazy, we load and search in the lazy config
@ -264,7 +265,8 @@ class UserConfig implements IUserConfig {
$values = array_filter(
$this->formatAppValues($userId, $app, ($this->fastCache[$userId][$app] ?? []) + ($this->lazyCache[$userId][$app] ?? []), $filtered),
function (string $key) use ($prefix): bool {
return str_starts_with($key, $prefix); // filter values based on $prefix
// filter values based on $prefix
return str_starts_with($key, $prefix);
}, ARRAY_FILTER_USE_KEY
);
@ -713,7 +715,8 @@ class UserConfig implements IUserConfig {
): string {
$this->assertParams($userId, $app, $key);
if (!$this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, $type, default: $default)) {
return $default; // returns default if strictness of lexicon is set to WARNING (block and report)
// returns default if strictness of lexicon is set to WARNING (block and report)
return $default;
}
$this->loadConfig($userId, $lazy);
@ -1048,7 +1051,8 @@ class UserConfig implements IUserConfig {
): bool {
$this->assertParams($userId, $app, $key);
if (!$this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, $type, $flags)) {
return false; // returns false as database is not updated
// returns false as database is not updated
return false;
}
$this->loadConfig($userId, $lazy);
@ -1101,7 +1105,8 @@ class UserConfig implements IUserConfig {
$inserted = true;
} catch (DBException $e) {
if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e; // TODO: throw exception or just log and returns false !?
// TODO: throw exception or just log and returns false !?
throw $e;
}
}
}
@ -1196,7 +1201,8 @@ class UserConfig implements IUserConfig {
public function updateType(string $userId, string $app, string $key, ValueType $type = ValueType::MIXED): bool {
$this->assertParams($userId, $app, $key);
$this->loadConfigAll($userId);
$this->isLazy($userId, $app, $key); // confirm key exists
// confirm key exists
$this->isLazy($userId, $app, $key);
$update = $this->connection->getQueryBuilder();
$update->update('preferences')
@ -1288,7 +1294,8 @@ class UserConfig implements IUserConfig {
}
}
$this->clearCacheAll(); // we clear all cache
// we clear all cache
$this->clearCacheAll();
}
/**
@ -1371,7 +1378,8 @@ class UserConfig implements IUserConfig {
}
}
$this->clearCacheAll(); // we clear all cache
// we clear all cache
$this->clearCacheAll();
}
/**
@ -1794,6 +1802,14 @@ class UserConfig implements IUserConfig {
}
/**
* will change referenced $value with the decrypted value in case of encrypted (sensitive value)
*
* @param string $userId
* @param string $app
* @param string $key
* @param string $value
*/
private function decryptSensitiveValue(string $userId, string $app, string $key, string &$value): void {
if (!$this->isFlagged(self::FLAG_SENSITIVE, $this->valueDetails[$userId][$app][$key]['flags'] ?? 0)) {
return;
@ -1821,6 +1837,7 @@ class UserConfig implements IUserConfig {
*
* @throws UnknownKeyException
* @throws TypeConflictException
* @return bool FALSE if conflict with defined lexicon were observed in the process
*/
private function matchAndApplyLexiconDefinition(
string $userId,
@ -1874,16 +1891,12 @@ class UserConfig implements IUserConfig {
* ],
*
* The entry is converted to string to fit the expected type when managing default value
*
* @param string $appId
* @param ConfigLexiconEntry $configValue
*
* @return string|null
*/
private function getSystemDefault(string $appId, ConfigLexiconEntry $configValue): ?string {
$default = $this->config->getSystemValue('lexicon.default.userconfig', [])[$appId][$configValue->getKey()] ?? null;
if ($default === null) {
return null; // no system default, using default default.
// no system default, using default default.
return null;
}
return $configValue->convertToString($default);

@ -3,7 +3,7 @@
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace NCU\Config\Lexicon;

@ -101,11 +101,6 @@ class GetConfigTest extends TestCase {
->method('getDetails')
->with('app-name', $configName)
->willReturn(['value' => $value]);
} else {
$this->config->expects($this->once())
->method('getValueMixed')
->with('app-name', $configName, $defaultValue)
->willReturn($defaultValue);
}
}

Loading…
Cancel
Save