Skip to content

Commit

Permalink
OXDEV-7646 Remove usage of ID in DataTypes
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Dec 4, 2023
1 parent 6e68112 commit 9b8abd8
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 173 deletions.
5 changes: 2 additions & 3 deletions src/Setting/DataType/BooleanSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@

use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;
use TheCodingMachine\GraphQLite\Types\ID;

#[Type]
final class BooleanSetting
{
public function __construct(
private ID $name,
private string $name,
private bool $value
) {
}

#[Field]
public function getName(): ID
public function getName(): string
{
return $this->name;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Setting/DataType/FloatSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
final class FloatSetting
{
public function __construct(
private ID $name,
private string $name,
private float $value
) {
}

#[Field]
public function getName(): ID
public function getName(): string
{
return $this->name;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Setting/DataType/IntegerSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@

use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;
use TheCodingMachine\GraphQLite\Types\ID;

#[Type]
final class IntegerSetting
{
public function __construct(
private ID $name,
private string $name,
private int $value
) {
}

#[Field]
public function getName(): ID
public function getName(): string
{
return $this->name;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Setting/DataType/SettingType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;
use TheCodingMachine\GraphQLite\Types\ID;

#[Type]
final class SettingType
{
public function __construct(
private ID $name,
private string $name,
private string $type
) {
}

#[Field]
public function getName(): ID
public function getName(): string
{
return $this->name;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Setting/DataType/StringSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@

use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;
use TheCodingMachine\GraphQLite\Types\ID;

#[Type]
final class StringSetting
{
public function __construct(
private ID $name,
private string $name,
private string $value
) {
}

#[Field]
public function getName(): ID
public function getName(): string
{
return $this->name;
}
Expand Down
33 changes: 16 additions & 17 deletions src/Setting/Service/ModuleSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\SettingType;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ModuleSettingRepositoryInterface;
use TheCodingMachine\GraphQLite\Types\ID;

final class ModuleSettingService implements ModuleSettingServiceInterface
{
Expand All @@ -29,77 +28,77 @@ public function __construct(
public function getIntegerSetting(string $name, string $moduleId): IntegerSetting
{
return new IntegerSetting(
new ID($name),
$this->moduleSettingRepository->getIntegerSetting((string)$name, $moduleId)
$name,
$this->moduleSettingRepository->getIntegerSetting($name, $moduleId)
);
}

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

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

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

public function getCollectionSetting(string $name, string $moduleId): StringSetting
{
$collection = $this->moduleSettingRepository->getCollectionSetting((string)$name, $moduleId);
$collection = $this->moduleSettingRepository->getCollectionSetting($name, $moduleId);

return new StringSetting(
new ID($name),
$name,
$this->jsonService->jsonEncodeArray($collection)
);
}

public function changeIntegerSetting(string $name, int $value, string $moduleId): IntegerSetting
{
$this->moduleSettingRepository->saveIntegerSetting((string)$name, $value, $moduleId);
$this->moduleSettingRepository->saveIntegerSetting($name, $value, $moduleId);

return $this->getIntegerSetting($name, $moduleId);
}

public function changeFloatSetting(string $name, float $value, string $moduleId): FloatSetting
{
$this->moduleSettingRepository->saveFloatSetting((string)$name, $value, $moduleId);
$this->moduleSettingRepository->saveFloatSetting($name, $value, $moduleId);

return $this->getFloatSetting($name, $moduleId);
}

public function changeBooleanSetting(string $name, bool $value, string $moduleId): BooleanSetting
{
$this->moduleSettingRepository->saveBooleanSetting((string)$name, $value, $moduleId);
$this->moduleSettingRepository->saveBooleanSetting($name, $value, $moduleId);

return $this->getBooleanSetting($name, $moduleId);
}

public function changeStringSetting(string $name, string $value, string $moduleId): StringSetting
{
$this->moduleSettingRepository->saveStringSetting((string)$name, $value, $moduleId);
$this->moduleSettingRepository->saveStringSetting($name, $value, $moduleId);

return $this->getStringSetting($name, $moduleId);
}

public function changeCollectionSetting(string $name, string $value, string $moduleId): StringSetting
{
$this->moduleSettingRepository->saveCollectionSetting(
(string)$name,
$name,
$this->jsonService->jsonDecodeCollection($value),
$moduleId
);
Expand All @@ -116,7 +115,7 @@ public function getSettingsList(string $moduleId): array
$settingTypes = [];
/** @var Setting $setting */
foreach ($settingsList as $setting) {
$settingTypes[] = new SettingType(new ID($setting->getName()), $setting->getType());
$settingTypes[] = new SettingType($setting->getName(), $setting->getType());
}

return $settingTypes;
Expand Down
17 changes: 8 additions & 9 deletions src/Setting/Service/ShopSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\SettingType;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ShopSettingRepositoryInterface;
use TheCodingMachine\GraphQLite\Types\ID;

final class ShopSettingService implements ShopSettingServiceInterface
{
Expand All @@ -28,47 +27,47 @@ public function __construct(
public function getIntegerSetting(string $name): IntegerSetting
{
$integer = $this->shopSettingRepository->getInteger($name);
return new IntegerSetting(new ID($name), $integer);
return new IntegerSetting($name, $integer);
}

public function getFloatSetting(string $name): FloatSetting
{
$float = $this->shopSettingRepository->getFloat($name);
return new FloatSetting(new ID($name), $float);
return new FloatSetting($name, $float);
}

public function getBooleanSetting(string $name): BooleanSetting
{
$bool = $this->shopSettingRepository->getBoolean($name);
return new BooleanSetting(new ID($name), $bool);
return new BooleanSetting($name, $bool);
}

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

public function getSelectSetting(string $name): StringSetting
{
$select = $this->shopSettingRepository->getSelect($name);
return new StringSetting(new ID($name), $select);
return new StringSetting($name, $select);
}

public function getCollectionSetting(string $name): StringSetting
{
$collectionString = $this->shopSettingRepository->getCollection($name);
$collectionEncodingResult = $this->jsonService->jsonEncodeArray($collectionString);

return new StringSetting(new ID($name), $collectionEncodingResult);
return new StringSetting($name, $collectionEncodingResult);
}

public function getAssocCollectionSetting(string $name): StringSetting
{
$assocCollectionString = $this->shopSettingRepository->getAssocCollection($name);
$assocCollectionEncodingResult = $this->jsonService->jsonEncodeArray($assocCollectionString);

return new StringSetting(new ID($name), $assocCollectionEncodingResult);
return new StringSetting($name, $assocCollectionEncodingResult);
}

/**
Expand All @@ -79,7 +78,7 @@ public function getSettingsList(): array
$settingsList = $this->shopSettingRepository->getSettingsList();
$settingsTypeList = [];
foreach ($settingsList as $name => $type) {
$settingsTypeList[] = new SettingType(new ID($name), $type);
$settingsTypeList[] = new SettingType($name, $type);
}

return $settingsTypeList;
Expand Down
17 changes: 8 additions & 9 deletions src/Setting/Service/ThemeSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OxidEsales\GraphQL\ConfigurationAccess\Setting\DataType\StringSetting;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\InvalidCollectionException;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure\ThemeSettingRepositoryInterface;
use TheCodingMachine\GraphQLite\Types\ID;

final class ThemeSettingService implements ThemeSettingServiceInterface
{
Expand All @@ -29,47 +28,47 @@ public function __construct(
public function getIntegerSetting(string $name, string $themeId): IntegerSetting
{
$integer = $this->themeSettingRepository->getInteger($name, $themeId);
return new IntegerSetting(new ID($name), $integer);
return new IntegerSetting($name, $integer);
}

public function getFloatSetting(string $name, string $themeId): FloatSetting
{
$float = $this->themeSettingRepository->getFloat($name, $themeId);
return new FloatSetting(new ID($name), $float);
return new FloatSetting($name, $float);
}

public function getBooleanSetting(string $name, string $themeId): BooleanSetting
{
$bool = $this->themeSettingRepository->getBoolean($name, $themeId);
return new BooleanSetting(new ID($name), $bool);
return new BooleanSetting($name, $bool);
}

public function getStringSetting(string $name, string $themeId): StringSetting
{
$string = $this->themeSettingRepository->getString($name, $themeId);
return new StringSetting(new ID($name), $string);
return new StringSetting($name, $string);
}

public function getSelectSetting(string $name, string $themeId): StringSetting
{
$select = $this->themeSettingRepository->getSelect($name, $themeId);
return new StringSetting(new ID($name), $select);
return new StringSetting($name, $select);
}

public function getCollectionSetting(string $name, string $themeId): StringSetting
{
$collection = $this->themeSettingRepository->getCollection($name, $themeId);
$collectionEncodingResult = $this->jsonService->jsonEncodeArray($collection);

return new StringSetting(new ID($name), $collectionEncodingResult);
return new StringSetting($name, $collectionEncodingResult);
}

public function getAssocCollectionSetting(string $name, string $themeId): StringSetting
{
$assocCollection = $this->themeSettingRepository->getAssocCollection($name, $themeId);
$collectionEncodingResult = $this->jsonService->jsonEncodeArray($assocCollection);

return new StringSetting(new ID($name), $collectionEncodingResult);
return new StringSetting($name, $collectionEncodingResult);
}

/**
Expand All @@ -80,7 +79,7 @@ public function getSettingsList(string $themeId): array
$settingsList = $this->themeSettingRepository->getSettingsList($themeId);
$settingsTypeList = [];
foreach ($settingsList as $name => $type) {
$settingsTypeList[] = new SettingType(new ID($name), $type);
$settingsTypeList[] = new SettingType($name, $type);
}

return $settingsTypeList;
Expand Down
Loading

0 comments on commit 9b8abd8

Please sign in to comment.