diff --git a/Makefile b/Makefile index 782df10b..ecb1afd7 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ export COMPOSE_PROJECT_NAME=settings export MIGRATIONS_NAMESPACE=MonsieurBiz\\SyliusSettingsPlugin\\Migrations export USER_UID=$(shell id -u) PLUGIN_NAME=sylius-${COMPOSE_PROJECT_NAME}-plugin -COMPOSE=docker-compose +COMPOSE=docker compose YARN=yarn ### diff --git a/src/Command/SetSettingsCommand.php b/src/Command/SetSettingsCommand.php index f79a04d4..fd74eb7b 100644 --- a/src/Command/SetSettingsCommand.php +++ b/src/Command/SetSettingsCommand.php @@ -94,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $settings = $this->settingsRegistry->getByAlias($alias); if (null === $settings) { - throw new SettingsException(sprintf('The alias "%s" is not valid.', $alias)); + throw new SettingsException(\sprintf('The alias "%s" is not valid.', $alias)); } ['vendor' => $vendor, 'plugin' => $plugin] = $settings->getAliasAsArray(); @@ -114,12 +114,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->settingManager->persist($setting); $this->settingManager->flush(); } catch (Exception $e) { - $output->writeln(sprintf('%s', $e->getMessage())); + $output->writeln(\sprintf('%s', $e->getMessage())); return Command::FAILURE; } - $output->writeln(sprintf('%s', 'The setting has been saved')); + $output->writeln(\sprintf('%s', 'The setting has been saved')); return Command::SUCCESS; } diff --git a/src/Controller/SettingsController.php b/src/Controller/SettingsController.php index 638c698e..7f9dc67b 100644 --- a/src/Controller/SettingsController.php +++ b/src/Controller/SettingsController.php @@ -68,7 +68,7 @@ public function formAction(Request $request, RegistryInterface $registry, string [ 'settings' => $settings, 'form_event' => 'monsieurbiz.settings.form', - 'form_event_dedicated' => sprintf('monsieurbiz.settings.form.%s', $settings->getAlias()), + 'form_event_dedicated' => \sprintf('monsieurbiz.settings.form.%s', $settings->getAlias()), 'form' => $form->createView(), ] ); diff --git a/src/DependencyInjection/InstantiateSettingsPass.php b/src/DependencyInjection/InstantiateSettingsPass.php index ad57a850..61fc1a19 100644 --- a/src/DependencyInjection/InstantiateSettingsPass.php +++ b/src/DependencyInjection/InstantiateSettingsPass.php @@ -70,7 +70,7 @@ private function validateSettingsResource(string $class): void { $classImplements = (array) (class_implements($class) ?: []); if (!\in_array(SettingsInterface::class, $classImplements, true)) { - throw new InvalidArgumentException(sprintf('Class "%s" must implement "%s" to be registered as a Settings resource.', $class, SettingsInterface::class)); + throw new InvalidArgumentException(\sprintf('Class "%s" must implement "%s" to be registered as a Settings resource.', $class, SettingsInterface::class)); } } diff --git a/src/Entity/Setting/Setting.php b/src/Entity/Setting/Setting.php index c0bca1a3..0856c162 100644 --- a/src/Entity/Setting/Setting.php +++ b/src/Entity/Setting/Setting.php @@ -260,7 +260,7 @@ private function getTypeFromValue($value): string $type = \gettype($value); if (!isset($types[$type])) { - throw new LogicException(sprintf('Impossible to match the type of the value. (%s)', $type)); + throw new LogicException(\sprintf('Impossible to match the type of the value. (%s)', $type)); } return $types[$type]($value); /** @phpstan-ignore-line */ diff --git a/src/Exception/SettingsAlreadyExistsException.php b/src/Exception/SettingsAlreadyExistsException.php index 73e4c113..3ba622d7 100644 --- a/src/Exception/SettingsAlreadyExistsException.php +++ b/src/Exception/SettingsAlreadyExistsException.php @@ -20,7 +20,7 @@ final class SettingsAlreadyExistsException extends SettingsException public function __construct(SettingsInterface $settings) { parent::__construct( - sprintf("Settings instance aliased '%s' already exists.", $settings->getAlias()) + \sprintf("Settings instance aliased '%s' already exists.", $settings->getAlias()) ); } } diff --git a/src/Processor/SettingsProcessor.php b/src/Processor/SettingsProcessor.php index 4bd9becb..ac2b5d6c 100644 --- a/src/Processor/SettingsProcessor.php +++ b/src/Processor/SettingsProcessor.php @@ -55,16 +55,16 @@ private function getChannelIdAndLocaleCodeFromSettingKey(string $settingKey): ar { switch (true) { // Default website + Default locale - case sprintf('%1$s-%1$s', Settings::DEFAULT_KEY) === $settingKey: + case \sprintf('%1$s-%1$s', Settings::DEFAULT_KEY) === $settingKey: return [null, null]; // Default website + locale - case 1 === preg_match(sprintf('`^%1$s-(?!%1$s)(?P.+)$`', Settings::DEFAULT_KEY), $settingKey, $matches): + case 1 === preg_match(\sprintf('`^%1$s-(?!%1$s)(?P.+)$`', Settings::DEFAULT_KEY), $settingKey, $matches): return [null, $matches['localeCode']]; // Website + default locale - case 1 === preg_match(sprintf('`^channel-(?P[0-9]+)-%1$s$`', Settings::DEFAULT_KEY), $settingKey, $matches): + case 1 === preg_match(\sprintf('`^channel-(?P[0-9]+)-%1$s$`', Settings::DEFAULT_KEY), $settingKey, $matches): return [(int) $matches['channelId'], null]; // Website + locale - case 1 === preg_match(sprintf('`^channel-(?P[0-9]+)-(?!%1$s)(?P.+)$`', Settings::DEFAULT_KEY), $settingKey, $matches): + case 1 === preg_match(\sprintf('`^channel-(?P[0-9]+)-(?!%1$s)(?P.+)$`', Settings::DEFAULT_KEY), $settingKey, $matches): return [(int) $matches['channelId'], $matches['localeCode']]; default: throw new LogicException("Format of the setting's key is incorrect."); @@ -100,7 +100,7 @@ private function removeUnusedSettings(array &$data, array $settings): void // Manage defaults, and remove actual settings with "use default value" checked foreach ($data as $key => $value) { // Is the setting a "use default value"? - if (1 === preg_match(sprintf('`^(?P.*)(?:___%1$s)$`', Settings::DEFAULT_KEY), $key, $matches)) { + if (1 === preg_match(\sprintf('`^(?P.*)(?:___%1$s)$`', Settings::DEFAULT_KEY), $key, $matches)) { if (true === $value) { if (isset($settings[$matches['key']])) { $this->entityManager->remove($settings[$matches['key']]); diff --git a/src/Provider/SettingProvider.php b/src/Provider/SettingProvider.php index bdb6f47a..39c71cda 100644 --- a/src/Provider/SettingProvider.php +++ b/src/Provider/SettingProvider.php @@ -62,7 +62,7 @@ public function validateType(?string $type): void { $types = Setting::getAllStorageTypes(); if (!\in_array($type, $types, true)) { - throw new Exception(sprintf('The type "%s" is not valid. Valid types are: %s', $type, implode(', ', $types))); + throw new Exception(\sprintf('The type "%s" is not valid. Valid types are: %s', $type, implode(', ', $types))); } } diff --git a/src/Provider/SettingsProvider.php b/src/Provider/SettingsProvider.php index 47a2eeca..4bcb8047 100644 --- a/src/Provider/SettingsProvider.php +++ b/src/Provider/SettingsProvider.php @@ -54,6 +54,6 @@ public function getSettingValueByChannelAndLocale( return $settingsInstance->getCurrentValue($channel, $locale, $path); } - throw new SettingsException(sprintf('Cannot fetch setting %s - %s', $alias, $path)); + throw new SettingsException(\sprintf('Cannot fetch setting %s - %s', $alias, $path)); } } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 4037b353..05bc491e 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -38,3 +38,7 @@ services: class: MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProvider MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProviderInterface: '@monsieurbiz.settings.provider' + + MonsieurBiz\SyliusSettingsPlugin\Factory\SettingFactory: + arguments: + $className: 'MonsieurBiz\SyliusSettingsPlugin\Entity\Setting\Setting' diff --git a/src/Settings/Metadata.php b/src/Settings/Metadata.php index 854a9b45..f1602aa1 100644 --- a/src/Settings/Metadata.php +++ b/src/Settings/Metadata.php @@ -71,7 +71,7 @@ public function getName(bool $aliased = false): string public function getParameter(string $name): mixed { if (!$this->hasParameter($name)) { - throw new InvalidArgumentException(sprintf('Parameter "%s" is not configured for resource "%s".', $name, $this->getAlias())); + throw new InvalidArgumentException(\sprintf('Parameter "%s" is not configured for resource "%s".', $name, $this->getAlias())); } return $this->parameters[$name]; @@ -95,7 +95,7 @@ public function getDefaultValues(): array public function getClass(string $name): string { if (!$this->hasClass($name)) { - throw new InvalidArgumentException(sprintf('Class "%s" is not configured for resource "%s".', $name, $this->getAlias())); + throw new InvalidArgumentException(\sprintf('Class "%s" is not configured for resource "%s".', $name, $this->getAlias())); } return $this->parameters['classes'][$name]; @@ -108,13 +108,13 @@ public function hasClass(string $name): bool public function getServiceId(string $serviceName): string { - return sprintf('%s.%s.%s', $this->applicationName, $serviceName, $this->alias($this->name)); + return \sprintf('%s.%s.%s', $this->applicationName, $serviceName, $this->alias($this->name)); } private static function parseAlias(string $alias): array { if (!str_contains($alias, '.')) { - throw new InvalidArgumentException(sprintf('Invalid alias "%s" supplied, it should conform to the following format ".".', $alias)); + throw new InvalidArgumentException(\sprintf('Invalid alias "%s" supplied, it should conform to the following format ".".', $alias)); } return explode('.', $alias); diff --git a/src/Settings/Metadata/Registry.php b/src/Settings/Metadata/Registry.php index 13476d29..67ca5470 100644 --- a/src/Settings/Metadata/Registry.php +++ b/src/Settings/Metadata/Registry.php @@ -30,7 +30,7 @@ final class Registry implements RegistryInterface public function get(string $alias): MetadataInterface { if (!\array_key_exists($alias, $this->metadata)) { - throw new InvalidArgumentException(sprintf('Resource "%s" does not exist.', $alias)); + throw new InvalidArgumentException(\sprintf('Resource "%s" does not exist.', $alias)); } return $this->metadata[$alias]; diff --git a/src/Settings/Settings.php b/src/Settings/Settings.php index 7fac371b..067dcf42 100644 --- a/src/Settings/Settings.php +++ b/src/Settings/Settings.php @@ -83,7 +83,7 @@ public function getFormClass(): string $className = $this->metadata->getClass('form'); $parentClassNames = (array) (class_parents($className) ?: []); if (!\in_array(AbstractSettingsType::class, $parentClassNames, true)) { - throw new SettingsException(sprintf('Class %s should extend %s', $className, AbstractSettingsType::class)); + throw new SettingsException(\sprintf('Class %s should extend %s', $className, AbstractSettingsType::class)); } return $className; @@ -220,10 +220,10 @@ private function getCacheTags(?ChannelInterface $channel, ?string $localeCode, a { return array_merge([ $this->getAlias(), - sprintf('vendor.%s', $this->getAliasAsArray()['vendor']), - sprintf('plugin.%s', $this->getAliasAsArray()['plugin']), - sprintf('channel.%s', $channel?->getCode() ?? self::DEFAULT_KEY), - sprintf('locale.%s', $localeCode ?? self::DEFAULT_KEY), + \sprintf('vendor.%s', $this->getAliasAsArray()['vendor']), + \sprintf('plugin.%s', $this->getAliasAsArray()['plugin']), + \sprintf('channel.%s', $channel?->getCode() ?? self::DEFAULT_KEY), + \sprintf('locale.%s', $localeCode ?? self::DEFAULT_KEY), ], $extra); } }