Skip to content

Commit 4f0d563

Browse files
committed
fix(lexicon): convert instead of cast
Signed-off-by: Maxence Lange <[email protected]>
1 parent 295f050 commit 4f0d563

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

apps/provisioning_api/lib/Controller/AppConfigController.php

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

1111
use OC\AppConfig;
1212
use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException;
13+
use OC\Config\ConfigManager;
1314
use OCP\App\IAppManager;
1415
use OCP\AppFramework\Http;
1516
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
@@ -38,6 +39,7 @@ public function __construct(
3839
private IGroupManager $groupManager,
3940
private IManager $settingManager,
4041
private IAppManager $appManager,
42+
private readonly ConfigManager $configManager,
4143
) {
4244
parent::__construct($appName, $request);
4345
}
@@ -147,11 +149,11 @@ public function setValue(string $app, string $key, string $value): DataResponse
147149

148150
/** @psalm-suppress InternalMethod */
149151
match ($type) {
150-
IAppConfig::VALUE_BOOL, ValueType::BOOL => $this->appConfig->setValueBool($app, $key, (bool)$value),
151-
IAppConfig::VALUE_FLOAT, ValueType::FLOAT => $this->appConfig->setValueFloat($app, $key, (float)$value),
152-
IAppConfig::VALUE_INT, ValueType::INT => $this->appConfig->setValueInt($app, $key, (int)$value),
152+
IAppConfig::VALUE_BOOL, ValueType::BOOL => $this->appConfig->setValueBool($app, $key, $this->configManager->convertToBool($value)),
153+
IAppConfig::VALUE_FLOAT, ValueType::FLOAT => $this->appConfig->setValueFloat($app, $key, $this->configManager->convertToFloat($value)),
154+
IAppConfig::VALUE_INT, ValueType::INT => $this->appConfig->setValueInt($app, $key, $this->configManager->convertToInt($value)),
153155
IAppConfig::VALUE_STRING, ValueType::STRING => $this->appConfig->setValueString($app, $key, $value),
154-
IAppConfig::VALUE_ARRAY, ValueType::ARRAY => $this->appConfig->setValueArray($app, $key, \json_decode($value, true)),
156+
IAppConfig::VALUE_ARRAY, ValueType::ARRAY => $this->appConfig->setValueArray($app, $key, $this->configManager->convertToArray($value)),
155157
default => $this->appConfig->setValueMixed($app, $key, $value),
156158
};
157159

apps/provisioning_api/tests/Controller/AppConfigControllerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OCA\Provisioning_API\Tests\Controller;
99

1010
use OC\AppConfig;
11+
use OC\Config\ConfigManager;
1112
use OCA\Provisioning_API\Controller\AppConfigController;
1213
use OCP\App\IAppManager;
1314
use OCP\AppFramework\Http;
@@ -38,6 +39,7 @@ class AppConfigControllerTest extends TestCase {
3839
private IManager&MockObject $settingManager;
3940
private IGroupManager&MockObject $groupManager;
4041
private IAppManager $appManager;
42+
private ConfigManager $configManager;
4143

4244
protected function setUp(): void {
4345
parent::setUp();
@@ -48,6 +50,7 @@ protected function setUp(): void {
4850
$this->settingManager = $this->createMock(IManager::class);
4951
$this->groupManager = $this->createMock(IGroupManager::class);
5052
$this->appManager = Server::get(IAppManager::class);
53+
$this->configManager = Server::get(ConfigManager::class);
5154
}
5255

5356
/**
@@ -67,6 +70,7 @@ protected function getInstance(array $methods = []) {
6770
$this->groupManager,
6871
$this->settingManager,
6972
$this->appManager,
73+
$this->configManager,
7074
);
7175
} else {
7276
return $this->getMockBuilder(AppConfigController::class)
@@ -79,6 +83,7 @@ protected function getInstance(array $methods = []) {
7983
$this->groupManager,
8084
$this->settingManager,
8185
$this->appManager,
86+
$this->configManager,
8287
])
8388
->onlyMethods($methods)
8489
->getMock();

0 commit comments

Comments
 (0)