Skip to content

Commit 28acc00

Browse files
committed
fix(lexicon): syntax
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent bd4a154 commit 28acc00

4 files changed

Lines changed: 29 additions & 28 deletions

File tree

lib/private/Config/Lexicon/CoreConfigLexicon.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44
/**
55
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
6-
* SPDX-License-Identifier: AGPL-3.0-only
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
88

99
namespace OC\Config\Lexicon;
@@ -17,19 +17,13 @@
1717
* ConfigLexicon for 'core' app/user configs
1818
*/
1919
class CoreConfigLexicon implements IConfigLexicon {
20-
/**
21-
* @inheritDoc
22-
* @return ConfigLexiconStrictness
23-
* @since 31.0.0
24-
*/
2520
public function getStrictness(): ConfigLexiconStrictness {
2621
return ConfigLexiconStrictness::IGNORE;
2722
}
2823

2924
/**
3025
* @inheritDoc
3126
* @return ConfigLexiconEntry[]
32-
* @since 31.0.0
3327
*/
3428
public function getAppConfigs(): array {
3529
return [
@@ -40,7 +34,6 @@ public function getAppConfigs(): array {
4034
/**
4135
* @inheritDoc
4236
* @return ConfigLexiconEntry[]
43-
* @since 31.0.0
4437
*/
4538
public function getUserConfigs(): array {
4639
return [

lib/private/Config/UserConfig.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ public function isLazy(string $userId, string $app, string $key): bool {
229229
// there is a huge probability the non-lazy config are already loaded
230230
// meaning that we can start by only checking if a current non-lazy key exists
231231
if ($this->hasKey($userId, $app, $key, false)) {
232-
return false; // meaning key is not lazy.
232+
// meaning key is not lazy.
233+
return false;
233234
}
234235

235236
// as key is not found as non-lazy, we load and search in the lazy config
@@ -264,7 +265,8 @@ public function getValues(
264265
$values = array_filter(
265266
$this->formatAppValues($userId, $app, ($this->fastCache[$userId][$app] ?? []) + ($this->lazyCache[$userId][$app] ?? []), $filtered),
266267
function (string $key) use ($prefix): bool {
267-
return str_starts_with($key, $prefix); // filter values based on $prefix
268+
// filter values based on $prefix
269+
return str_starts_with($key, $prefix);
268270
}, ARRAY_FILTER_USE_KEY
269271
);
270272

@@ -713,7 +715,8 @@ private function getTypedValue(
713715
): string {
714716
$this->assertParams($userId, $app, $key);
715717
if (!$this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, $type, default: $default)) {
716-
return $default; // returns default if strictness of lexicon is set to WARNING (block and report)
718+
// returns default if strictness of lexicon is set to WARNING (block and report)
719+
return $default;
717720
}
718721
$this->loadConfig($userId, $lazy);
719722

@@ -1048,7 +1051,8 @@ private function setTypedValue(
10481051
): bool {
10491052
$this->assertParams($userId, $app, $key);
10501053
if (!$this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, $type, $flags)) {
1051-
return false; // returns false as database is not updated
1054+
// returns false as database is not updated
1055+
return false;
10521056
}
10531057
$this->loadConfig($userId, $lazy);
10541058

@@ -1101,7 +1105,8 @@ private function setTypedValue(
11011105
$inserted = true;
11021106
} catch (DBException $e) {
11031107
if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
1104-
throw $e; // TODO: throw exception or just log and returns false !?
1108+
// TODO: throw exception or just log and returns false !?
1109+
throw $e;
11051110
}
11061111
}
11071112
}
@@ -1196,7 +1201,8 @@ private function setTypedValue(
11961201
public function updateType(string $userId, string $app, string $key, ValueType $type = ValueType::MIXED): bool {
11971202
$this->assertParams($userId, $app, $key);
11981203
$this->loadConfigAll($userId);
1199-
$this->isLazy($userId, $app, $key); // confirm key exists
1204+
// confirm key exists
1205+
$this->isLazy($userId, $app, $key);
12001206

12011207
$update = $this->connection->getQueryBuilder();
12021208
$update->update('preferences')
@@ -1288,7 +1294,8 @@ public function updateGlobalSensitive(string $app, string $key, bool $sensitive)
12881294
}
12891295
}
12901296

1291-
$this->clearCacheAll(); // we clear all cache
1297+
// we clear all cache
1298+
$this->clearCacheAll();
12921299
}
12931300

12941301
/**
@@ -1371,7 +1378,8 @@ public function updateGlobalIndexed(string $app, string $key, bool $indexed): vo
13711378
}
13721379
}
13731380

1374-
$this->clearCacheAll(); // we clear all cache
1381+
// we clear all cache
1382+
$this->clearCacheAll();
13751383
}
13761384

13771385
/**
@@ -1794,6 +1802,14 @@ private function convertTypedValue(string $value, ValueType $type): string|int|f
17941802
}
17951803

17961804

1805+
/**
1806+
* will change referenced $value with the decrypted value in case of encrypted (sensitive value)
1807+
*
1808+
* @param string $userId
1809+
* @param string $app
1810+
* @param string $key
1811+
* @param string $value
1812+
*/
17971813
private function decryptSensitiveValue(string $userId, string $app, string $key, string &$value): void {
17981814
if (!$this->isFlagged(self::FLAG_SENSITIVE, $this->valueDetails[$userId][$app][$key]['flags'] ?? 0)) {
17991815
return;
@@ -1821,6 +1837,7 @@ private function decryptSensitiveValue(string $userId, string $app, string $key,
18211837
*
18221838
* @throws UnknownKeyException
18231839
* @throws TypeConflictException
1840+
* @return bool FALSE if conflict with defined lexicon were observed in the process
18241841
*/
18251842
private function matchAndApplyLexiconDefinition(
18261843
string $userId,
@@ -1874,16 +1891,12 @@ private function matchAndApplyLexiconDefinition(
18741891
* ],
18751892
*
18761893
* The entry is converted to string to fit the expected type when managing default value
1877-
*
1878-
* @param string $appId
1879-
* @param ConfigLexiconEntry $configValue
1880-
*
1881-
* @return string|null
18821894
*/
18831895
private function getSystemDefault(string $appId, ConfigLexiconEntry $configValue): ?string {
18841896
$default = $this->config->getSystemValue('lexicon.default.userconfig', [])[$appId][$configValue->getKey()] ?? null;
18851897
if ($default === null) {
1886-
return null; // no system default, using default default.
1898+
// no system default, using default default.
1899+
return null;
18871900
}
18881901

18891902
return $configValue->convertToString($default);

lib/unstable/Config/Lexicon/ConfigLexiconEntry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44
/**
55
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
6-
* SPDX-License-Identifier: AGPL-3.0-only
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
88

99
namespace NCU\Config\Lexicon;

tests/Core/Command/Config/App/GetConfigTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ public function testGet($configName, $value, $configExists, $defaultValue, $hasD
101101
->method('getDetails')
102102
->with('app-name', $configName)
103103
->willReturn(['value' => $value]);
104-
} else {
105-
$this->config->expects($this->once())
106-
->method('getValueMixed')
107-
->with('app-name', $configName, $defaultValue)
108-
->willReturn($defaultValue);
109104
}
110105
}
111106

0 commit comments

Comments
 (0)