Skip to content

Commit bd87605

Browse files
committed
fix(lexicon): shorter name for preset
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent ebffd65 commit bd87605

8 files changed

Lines changed: 38 additions & 38 deletions

File tree

core/Command/Config/Preset.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
namespace OC\Core\Command\Config;
88

9-
use NCU\Config\Lexicon\ConfigLexiconPreset;
9+
use NCU\Config\Lexicon\Preset;
1010
use OC\Config\ConfigManager;
1111
use OCP\IConfig;
1212
use Symfony\Component\Console\Command\Command;
@@ -48,14 +48,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4848
$this->configManager->setLexiconPreset($preset);
4949
}
5050

51-
$current = ConfigLexiconPreset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? ConfigLexiconPreset::NONE;
51+
$current = Preset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;
5252
$output->writeln('current preset: ' . $current->name);
5353
return 0;
5454
}
5555

56-
private function getEnum(string $name, ?array &$list = null): ?ConfigLexiconPreset {
56+
private function getEnum(string $name, ?array &$list = null): ?Preset {
5757
$list = [];
58-
foreach (ConfigLexiconPreset::cases() as $case) {
58+
foreach (Preset::cases() as $case) {
5959
$list[] = $case->name;
6060
if (strtolower($case->name) === strtolower($name)) {
6161
return $case;

lib/private/AppConfig.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use InvalidArgumentException;
1313
use JsonException;
1414
use NCU\Config\Lexicon\ConfigLexiconEntry;
15-
use NCU\Config\Lexicon\ConfigLexiconPreset;
15+
use NCU\Config\Lexicon\Preset;
1616
use NCU\Config\Lexicon\ConfigLexiconStrictness;
1717
use NCU\Config\Lexicon\IConfigLexicon;
1818
use OC\AppFramework\Bootstrap\Coordinator;
@@ -65,7 +65,7 @@ class AppConfig implements IAppConfig {
6565
/** @var array<string, array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
6666
private array $configLexiconDetails = [];
6767
private bool $ignoreLexiconAliases = false;
68-
private ?ConfigLexiconPreset $configLexiconPreset = null;
68+
private ?Preset $configLexiconPreset = null;
6969
/** @var ?array<string, string> */
7070
private ?array $appVersionsCache = null;
7171

@@ -1730,9 +1730,9 @@ public function ignoreLexiconAliases(bool $ignore): void {
17301730
$this->ignoreLexiconAliases = $ignore;
17311731
}
17321732

1733-
private function getLexiconPreset(): ConfigLexiconPreset {
1733+
private function getLexiconPreset(): Preset {
17341734
if ($this->configLexiconPreset === null) {
1735-
$this->configLexiconPreset = ConfigLexiconPreset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? ConfigLexiconPreset::NONE;
1735+
$this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;
17361736
}
17371737

17381738
return $this->configLexiconPreset;

lib/private/Config/ConfigManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use NCU\Config\Exceptions\TypeConflictException;
1313
use NCU\Config\IUserConfig;
1414
use NCU\Config\Lexicon\ConfigLexiconEntry;
15-
use NCU\Config\Lexicon\ConfigLexiconPreset;
15+
use NCU\Config\Lexicon\Preset;
1616
use NCU\Config\ValueType;
1717
use OC\AppConfig;
1818
use OCP\App\IAppManager;
@@ -84,7 +84,7 @@ public function migrateConfigLexiconKeys(?string $appId = null): void {
8484
* store in config.php the new preset
8585
* refresh cached preset
8686
*/
87-
public function setLexiconPreset(ConfigLexiconPreset $preset): void {
87+
public function setLexiconPreset(Preset $preset): void {
8888
$this->config->setSystemValue(self::PRESET_CONFIGKEY, $preset->value);
8989
$this->loadConfigServices();
9090
$this->appConfig->clearCache();

lib/private/Config/UserConfig.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use NCU\Config\Exceptions\UnknownKeyException;
1717
use NCU\Config\IUserConfig;
1818
use NCU\Config\Lexicon\ConfigLexiconEntry;
19-
use NCU\Config\Lexicon\ConfigLexiconPreset;
19+
use NCU\Config\Lexicon\Preset;
2020
use NCU\Config\Lexicon\ConfigLexiconStrictness;
2121
use NCU\Config\ValueType;
2222
use OC\AppFramework\Bootstrap\Coordinator;
@@ -67,7 +67,7 @@ class UserConfig implements IUserConfig {
6767
/** @var array<string, array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
6868
private array $configLexiconDetails = [];
6969
private bool $ignoreLexiconAliases = false;
70-
private ?ConfigLexiconPreset $configLexiconPreset = null;
70+
private ?Preset $configLexiconPreset = null;
7171

7272
public function __construct(
7373
protected IDBConnection $connection,
@@ -2038,9 +2038,9 @@ public function ignoreLexiconAliases(bool $ignore): void {
20382038
$this->ignoreLexiconAliases = $ignore;
20392039
}
20402040

2041-
private function getLexiconPreset(): ConfigLexiconPreset {
2041+
private function getLexiconPreset(): Preset {
20422042
if ($this->configLexiconPreset === null) {
2043-
$this->configLexiconPreset = ConfigLexiconPreset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? ConfigLexiconPreset::NONE;
2043+
$this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;
20442044
}
20452045

20462046
return $this->configLexiconPreset;

lib/unstable/Config/Lexicon/ConfigLexiconEntry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function convertFromArray(array $default): string {
130130
* @return string|null NULL if no default is set
131131
* @experimental 31.0.0
132132
*/
133-
public function getDefault(ConfigLexiconPreset $preset): ?string {
133+
public function getDefault(Preset $preset): ?string {
134134
if ($this->default !== null) {
135135
return $this->default;
136136
}

lib/unstable/Config/Lexicon/ConfigLexiconPreset.php renamed to lib/unstable/Config/Lexicon/Preset.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
*
1414
* @see ConfigLexiconEntry::preset
1515
*
16-
* - **ConfigLexiconPreset::LARGE** - Large size organisation (> 50k accounts)
17-
* - **ConfigLexiconPreset::MEDIUM** - Medium size organisation (> 100 accounts)
18-
* - **ConfigLexiconPreset::SMALL** - Small size organisation (< 100 accounts)
19-
* - **ConfigLexiconPreset::SHARED** - Shared hosting
20-
* - **ConfigLexiconPreset::EDUCATION** - School/University
21-
* - **ConfigLexiconPreset::CLUB** - Club/Association
22-
* - **ConfigLexiconPreset::FAMILY** - Family
23-
* - **ConfigLexiconPreset::PRIVATE** - Private
16+
* - **Preset::LARGE** - Large size organisation (> 50k accounts)
17+
* - **Preset::MEDIUM** - Medium size organisation (> 100 accounts)
18+
* - **Preset::SMALL** - Small size organisation (< 100 accounts)
19+
* - **Preset::SHARED** - Shared hosting
20+
* - **Preset::EDUCATION** - School/University
21+
* - **Preset::CLUB** - Club/Association
22+
* - **Preset::FAMILY** - Family
23+
* - **Preset::PRIVATE** - Private
2424
*
2525
* @experimental 32.0.0
2626
*/
27-
enum ConfigLexiconPreset: int {
27+
enum Preset: int {
2828
/** @experimental 32.0.0 */
2929
case LARGE = 8;
3030
/** @experimental 32.0.0 */

tests/lib/Config/LexiconTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use NCU\Config\Exceptions\TypeConflictException;
1111
use NCU\Config\Exceptions\UnknownKeyException;
1212
use NCU\Config\IUserConfig;
13-
use NCU\Config\Lexicon\ConfigLexiconPreset;
13+
use NCU\Config\Lexicon\Preset;
1414
use OC\AppConfig;
1515
use OC\AppFramework\Bootstrap\Coordinator;
1616
use OC\Config\ConfigManager;
@@ -206,26 +206,26 @@ public function testAppConfigLexiconRenameInvertBoolean() {
206206
}
207207

208208
public function testAppConfigLexiconPreset() {
209-
$this->configManager->setLexiconPreset(ConfigLexiconPreset::FAMILY);
209+
$this->configManager->setLexiconPreset(Preset::FAMILY);
210210
$this->assertSame('family', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key3'));
211211
}
212212

213213
public function testAppConfigLexiconPresets() {
214-
$this->configManager->setLexiconPreset(ConfigLexiconPreset::MEDIUM);
214+
$this->configManager->setLexiconPreset(Preset::MEDIUM);
215215
$this->assertSame('club+medium', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key3'));
216-
$this->configManager->setLexiconPreset(ConfigLexiconPreset::FAMILY);
216+
$this->configManager->setLexiconPreset(Preset::FAMILY);
217217
$this->assertSame('family', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key3'));
218218
}
219219

220220
public function testUserConfigLexiconPreset() {
221-
$this->configManager->setLexiconPreset(ConfigLexiconPreset::FAMILY);
221+
$this->configManager->setLexiconPreset(Preset::FAMILY);
222222
$this->assertSame('family', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key3'));
223223
}
224224

225225
public function testUserConfigLexiconPresets() {
226-
$this->configManager->setLexiconPreset(ConfigLexiconPreset::MEDIUM);
226+
$this->configManager->setLexiconPreset(Preset::MEDIUM);
227227
$this->assertSame('club+medium', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key3'));
228-
$this->configManager->setLexiconPreset(ConfigLexiconPreset::FAMILY);
228+
$this->configManager->setLexiconPreset(Preset::FAMILY);
229229
$this->assertSame('family', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key3'));
230230
}
231231
}

tests/lib/Config/TestConfigLexicon_E.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use NCU\Config\IUserConfig;
1212
use NCU\Config\Lexicon\ConfigLexiconEntry;
13-
use NCU\Config\Lexicon\ConfigLexiconPreset;
13+
use NCU\Config\Lexicon\Preset;
1414
use NCU\Config\Lexicon\ConfigLexiconStrictness;
1515
use NCU\Config\Lexicon\IConfigLexicon;
1616
use NCU\Config\ValueType;
@@ -27,9 +27,9 @@ public function getAppConfigs(): array {
2727
return [
2828
new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IAppConfig::FLAG_SENSITIVE),
2929
new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false),
30-
new ConfigLexiconEntry('key3', ValueType::STRING, fn (ConfigLexiconPreset $p): string => match ($p) {
31-
ConfigLexiconPreset::FAMILY => 'family',
32-
ConfigLexiconPreset::CLUB, ConfigLexiconPreset::MEDIUM => 'club+medium',
30+
new ConfigLexiconEntry('key3', ValueType::STRING, fn (Preset $p): string => match ($p) {
31+
Preset::FAMILY => 'family',
32+
Preset::CLUB, Preset::MEDIUM => 'club+medium',
3333
default => 'none',
3434
}, 'test key'),
3535
];
@@ -39,9 +39,9 @@ public function getUserConfigs(): array {
3939
return [
4040
new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IUserConfig::FLAG_SENSITIVE),
4141
new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false),
42-
new ConfigLexiconEntry('key3', ValueType::STRING, fn (ConfigLexiconPreset $p): string => match ($p) {
43-
ConfigLexiconPreset::FAMILY => 'family',
44-
ConfigLexiconPreset::CLUB, ConfigLexiconPreset::MEDIUM => 'club+medium',
42+
new ConfigLexiconEntry('key3', ValueType::STRING, fn (Preset $p): string => match ($p) {
43+
Preset::FAMILY => 'family',
44+
Preset::CLUB, Preset::MEDIUM => 'club+medium',
4545
default => 'none',
4646
}, 'test key'),
4747
];

0 commit comments

Comments
 (0)