Skip to content

Commit

Permalink
OXDEV-7557 Cleanup using the ID and Graphql types in modules setting …
Browse files Browse the repository at this point in the history
…repository getters

Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 15, 2023
1 parent 4e65c47 commit 164151d
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 189 deletions.
39 changes: 10 additions & 29 deletions src/Setting/Infrastructure/ModuleSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\BooleanSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\FloatSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\IntegerSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting;
use TheCodingMachine\GraphQLite\Types\ID;

final class ModuleSettingRepository implements ModuleSettingRepositoryInterface
Expand All @@ -28,44 +24,29 @@ public function __construct(
) {
}

public function getIntegerSetting(ID $name, string $moduleId): IntegerSetting
public function getIntegerSetting(string $name, string $moduleId): int
{
$name = $name->val();
$value = $this->moduleSettingService->getInteger($name, $moduleId);

return new IntegerSetting(new ID($name), $value);
return $this->moduleSettingService->getInteger($name, $moduleId);
}

public function getFloatSetting(ID $name, string $moduleId): FloatSetting
public function getFloatSetting(string $name, string $moduleId): float
{
$name = $name->val();
$value = $this->moduleSettingService->getFloat($name, $moduleId);

return new FloatSetting(new ID($name), $value);
return $this->moduleSettingService->getFloat($name, $moduleId);
}

public function getBooleanSetting(ID $name, string $moduleId): BooleanSetting
public function getBooleanSetting(string $name, string $moduleId): bool
{
$name = $name->val();
$value = $this->moduleSettingService->getBoolean($name, $moduleId);

return new BooleanSetting(new ID($name), $value);
return $this->moduleSettingService->getBoolean($name, $moduleId);
}

public function getStringSetting(ID $name, string $moduleId): StringSetting
public function getStringSetting(string $name, string $moduleId): string
{
$name = $name->val();
$value = $this->moduleSettingService->getString($name, $moduleId);

return new StringSetting(new ID($name), (string)$value);
return (string)$this->moduleSettingService->getString($name, $moduleId);
}

public function getCollectionSetting(ID $name, string $moduleId): StringSetting
public function getCollectionSetting(string $name, string $moduleId): array
{
$name = $name->val();
$value = $this->moduleSettingService->getCollection($name, $moduleId);

return new StringSetting(new ID($name), json_encode($value));
return $this->moduleSettingService->getCollection($name, $moduleId);
}

public function saveIntegerSetting(ID $name, int $value, string $moduleId): void
Expand Down
14 changes: 5 additions & 9 deletions src/Setting/Infrastructure/ModuleSettingRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
namespace OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure;

use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\BooleanSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\FloatSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\IntegerSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting;
use TheCodingMachine\GraphQLite\Types\ID;

interface ModuleSettingRepositoryInterface
{
public function getIntegerSetting(ID $name, string $moduleId): IntegerSetting;
public function getIntegerSetting(string $name, string $moduleId): int;

public function getFloatSetting(ID $name, string $moduleId): FloatSetting;
public function getFloatSetting(string $name, string $moduleId): float;

public function getBooleanSetting(ID $name, string $moduleId): BooleanSetting;
public function getBooleanSetting(string $name, string $moduleId): bool;

public function getStringSetting(ID $name, string $moduleId): StringSetting;
public function getStringSetting(string $name, string $moduleId): string;

public function getCollectionSetting(ID $name, string $moduleId): StringSetting;
public function getCollectionSetting(string $name, string $moduleId): array;

public function saveIntegerSetting(ID $name, int $value, string $moduleId): void;

Expand Down
25 changes: 20 additions & 5 deletions src/Setting/Service/ModuleSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,42 @@ public function __construct(

public function getIntegerSetting(ID $name, string $moduleId): IntegerSetting
{
return $this->moduleSettingRepository->getIntegerSetting($name, $moduleId);
return new IntegerSetting(
$name,
$this->moduleSettingRepository->getIntegerSetting((string)$name, $moduleId)
);
}

public function getFloatSetting(ID $name, string $moduleId): FloatSetting
{
return $this->moduleSettingRepository->getFloatSetting($name, $moduleId);
return new FloatSetting(
$name,
$this->moduleSettingRepository->getFloatSetting((string)$name, $moduleId)
);
}

public function getBooleanSetting(ID $name, string $moduleId): BooleanSetting
{
return $this->moduleSettingRepository->getBooleanSetting($name, $moduleId);
return new BooleanSetting(
$name,
$this->moduleSettingRepository->getBooleanSetting((string)$name, $moduleId)
);
}

public function getStringSetting(ID $name, string $moduleId): StringSetting
{
return $this->moduleSettingRepository->getStringSetting($name, $moduleId);
return new StringSetting(
$name,
$this->moduleSettingRepository->getStringSetting((string)$name, $moduleId)
);
}

public function getCollectionSetting(ID $name, string $moduleId): StringSetting
{
return $this->moduleSettingRepository->getCollectionSetting($name, $moduleId);
return new StringSetting(
$name,
json_encode($this->moduleSettingRepository->getCollectionSetting((string)$name, $moduleId))
);
}

public function changeIntegerSetting(ID $name, int $value, string $moduleId): IntegerSetting
Expand Down
Loading

0 comments on commit 164151d

Please sign in to comment.