diff --git a/.github/workflows/recipe.yaml b/.github/workflows/recipe.yaml index 492a66ef..6b8aa5f0 100644 --- a/.github/workflows/recipe.yaml +++ b/.github/workflows/recipe.yaml @@ -19,21 +19,8 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.4', '8.0', '8.1'] - sylius: ['~1.8.0', '~1.9.0', '~1.10.0', '~1.11.0', '~1.12.0'] - exclude: - - php: 8.0 - sylius: '~1.8.0' - - php: 8.0 - sylius: '~1.9.0' - - php: 8.1 - sylius: '~1.8.0' - - php: 8.1 - sylius: '~1.9.0' - - php: 7.4 - sylius: '~1.11.0' - - php: 7.4 - sylius: '~1.12.0' + php: ['8.0', '8.1', '8.2'] + sylius: ['~1.10.0', '~1.11.0', '~1.12.0'] steps: - name: Setup PHP diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml index 97608b03..630420de 100644 --- a/.github/workflows/security.yaml +++ b/.github/workflows/security.yaml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.4', '8.0', '8.1'] + php: ['8.0', '8.1', '8.2'] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 9a5cad42..25bed714 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.0', '8.1'] + php: ['8.0', '8.1', '8.2'] env: SYMFONY_ARGS: --no-tls diff --git a/.php-version.dist b/.php-version.dist index b8eb0263..2983cad0 100644 --- a/.php-version.dist +++ b/.php-version.dist @@ -1 +1 @@ -8.1 +8.2 diff --git a/composer.json b/composer.json index db416cc8..45aff53a 100644 --- a/composer.json +++ b/composer.json @@ -5,10 +5,10 @@ "description": "Add a settings panel to your Sylius.", "license": "MIT", "require": { - "php": "~7.4|^8.0", + "php": "^8.0", "ext-mbstring": "*", "ext-json": "*", - "sylius/sylius": ">=1.8 <1.13" + "sylius/sylius": ">=1.10 <1.13" }, "require-dev": { "behat/behat": "^3.6.1", diff --git a/src/Command/SetSettingsCommand.php b/src/Command/SetSettingsCommand.php index 0edd9760..f79a04d4 100644 --- a/src/Command/SetSettingsCommand.php +++ b/src/Command/SetSettingsCommand.php @@ -22,12 +22,19 @@ use MonsieurBiz\SyliusSettingsPlugin\Settings\SettingsInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'monsieurbiz:settings:set', + description: 'Set a settings value for a given path', + aliases: ['mbiz:settings:set'], + hidden: false +)] class SetSettingsCommand extends Command { private const ARGUMENT_ALIAS = 'alias'; @@ -42,38 +49,20 @@ class SetSettingsCommand extends Command private const ARGUMENT_VALUE = 'value'; - private RegistryInterface $settingsRegistry; - - private ChannelRepositoryInterface $channelRepository; - - private EntityManagerInterface $settingManager; - - private SettingsFormatterInterface $settingsFormatter; - - private SettingProviderInterface $settingProvider; - - protected static $defaultName = 'monsieurbiz:settings:set'; - public function __construct( - RegistryInterface $settingsRegistry, - ChannelRepositoryInterface $channelRepository, - EntityManagerInterface $settingManager, - SettingsFormatterInterface $settingsFormatter, - SettingProviderInterface $settingProvider, + private RegistryInterface $settingsRegistry, + private ChannelRepositoryInterface $channelRepository, + private SettingProviderInterface $settingProvider, + private EntityManagerInterface $settingManager, + private SettingsFormatterInterface $settingsFormatter, string $name = null ) { - $this->settingsRegistry = $settingsRegistry; - $this->channelRepository = $channelRepository; - $this->settingManager = $settingManager; - $this->settingsFormatter = $settingsFormatter; - $this->settingProvider = $settingProvider; parent::__construct($name); } protected function configure(): void { $this - ->setDescription('Set a settings value for a given path') ->setHelp('This command allows you to set a settings value for a given path') ->addArgument(self::ARGUMENT_ALIAS, InputArgument::REQUIRED, 'Alias of the settings like {vendor}.{plugin} from the setting definition') ->addArgument(self::ARGUMENT_PATH, InputArgument::REQUIRED, 'Path of the settings') diff --git a/src/Controller/SettingsController.php b/src/Controller/SettingsController.php index d7be515c..f9a0c10b 100644 --- a/src/Controller/SettingsController.php +++ b/src/Controller/SettingsController.php @@ -25,35 +25,23 @@ final class SettingsController extends AbstractController { - private SettingsProcessorInterface $settingsProcessor; - - private MainSettingsFormTypeFactoryInterface $formFactory; - /** * SettingsController constructor. */ public function __construct( - SettingsProcessorInterface $settingsProcessor, - MainSettingsFormTypeFactoryInterface $formFactory + private SettingsProcessorInterface $settingsProcessor, + private MainSettingsFormTypeFactoryInterface $formFactory ) { - $this->settingsProcessor = $settingsProcessor; - $this->formFactory = $formFactory; } - /** - * @return Response - */ - public function indexAction(RegistryInterface $registry) + public function indexAction(RegistryInterface $registry): Response { return $this->render('@MonsieurBizSyliusSettingsPlugin/Crud/index.html.twig', [ 'settings' => $registry->getAllSettings(), ]); } - /** - * @return Response - */ - public function formAction(Request $request, RegistryInterface $registry, string $alias) + public function formAction(Request $request, RegistryInterface $registry, string $alias): Response { if (null === ($settings = $registry->getByAlias($alias))) { throw $this->createNotFoundException(); diff --git a/src/Factory/Form/MainSettingsFormTypeFactory.php b/src/Factory/Form/MainSettingsFormTypeFactory.php index 829253c6..eddf105a 100644 --- a/src/Factory/Form/MainSettingsFormTypeFactory.php +++ b/src/Factory/Form/MainSettingsFormTypeFactory.php @@ -24,23 +24,14 @@ final class MainSettingsFormTypeFactory implements MainSettingsFormTypeFactoryInterface { - private FormFactoryInterface $formFactory; - - private ChannelRepositoryInterface $channelRepository; - - private RepositoryInterface $localeRepository; - /** * MainSettingsFormTypeFactory constructor. */ public function __construct( - FormFactoryInterface $formFactory, - ChannelRepositoryInterface $channelRepository, - RepositoryInterface $localeRepository + private FormFactoryInterface $formFactory, + private ChannelRepositoryInterface $channelRepository, + private RepositoryInterface $localeRepository ) { - $this->formFactory = $formFactory; - $this->channelRepository = $channelRepository; - $this->localeRepository = $localeRepository; } public function createNew(SettingsInterface $settings, string $type, array $options = []): FormInterface diff --git a/src/Factory/SettingFactory.php b/src/Factory/SettingFactory.php index a7d74e23..ab614533 100644 --- a/src/Factory/SettingFactory.php +++ b/src/Factory/SettingFactory.php @@ -20,20 +20,11 @@ final class SettingFactory implements SettingFactoryInterface { - /** - * @var string - */ - private $className; - - public function __construct(string $className) + public function __construct(private string $className) { - $this->className = $className; } - /** - * @return SettingInterface - */ - public function createNew() + public function createNew(): SettingInterface { /** @var SettingInterface */ return new $this->className(); diff --git a/src/Fixture/Factory/SettingsFixtureFactory.php b/src/Fixture/Factory/SettingsFixtureFactory.php index 4008e675..90a060f0 100644 --- a/src/Fixture/Factory/SettingsFixtureFactory.php +++ b/src/Fixture/Factory/SettingsFixtureFactory.php @@ -26,26 +26,14 @@ class SettingsFixtureFactory extends AbstractExampleFactory { - private RegistryInterface $settingsRegistry; - private OptionsResolver $optionsResolver; - private ChannelRepositoryInterface $channelRepository; - - private SettingsFormatterInterface $settingsFormatter; - - private SettingProviderInterface $settingProvider; - public function __construct( - RegistryInterface $settingsRegistry, - ChannelRepositoryInterface $channelRepository, - SettingsFormatterInterface $settingsFormatter, - SettingProviderInterface $settingProvider + private RegistryInterface $settingsRegistry, + private ChannelRepositoryInterface $channelRepository, + private SettingProviderInterface $settingProvider, + private SettingsFormatterInterface $settingsFormatter ) { - $this->settingsRegistry = $settingsRegistry; - $this->channelRepository = $channelRepository; - $this->settingsFormatter = $settingsFormatter; - $this->settingProvider = $settingProvider; $this->optionsResolver = new OptionsResolver(); $this->configureOptions($this->optionsResolver); diff --git a/src/Form/MainSettingsType.php b/src/Form/MainSettingsType.php index 0865f6eb..23f5b1d4 100644 --- a/src/Form/MainSettingsType.php +++ b/src/Form/MainSettingsType.php @@ -27,19 +27,13 @@ final class MainSettingsType extends AbstractType implements MainSettingsTypeInterface { - private ChannelRepositoryInterface $channelRepository; - - private RepositoryInterface $localeRepository; - /** * MainSettingsType constructor. */ public function __construct( - ChannelRepositoryInterface $channelRepository, - RepositoryInterface $localeRepository + private ChannelRepositoryInterface $channelRepository, + private RepositoryInterface $localeRepository ) { - $this->channelRepository = $channelRepository; - $this->localeRepository = $localeRepository; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Formatter/SettingsFormatter.php b/src/Formatter/SettingsFormatter.php index 07115e45..7334e99e 100644 --- a/src/Formatter/SettingsFormatter.php +++ b/src/Formatter/SettingsFormatter.php @@ -20,13 +20,10 @@ class SettingsFormatter implements SettingsFormatterInterface { /** * @param int|float|string|array $value - * @param mixed $type - * - * @return mixed * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function formatValue($type, $value) + public function formatValue(mixed $type, $value): mixed { switch ($type) { case SettingInterface::STORAGE_TYPE_BOOLEAN: diff --git a/src/Formatter/SettingsFormatterInterface.php b/src/Formatter/SettingsFormatterInterface.php index 321885c1..f92310ef 100644 --- a/src/Formatter/SettingsFormatterInterface.php +++ b/src/Formatter/SettingsFormatterInterface.php @@ -17,9 +17,6 @@ interface SettingsFormatterInterface { /** * @param int|float|string|array $value - * @param mixed $type - * - * @return mixed */ - public function formatValue($type, $value); + public function formatValue(mixed $type, $value): mixed; } diff --git a/src/Menu/AdminMenuListener.php b/src/Menu/AdminMenuListener.php index 85447d44..f39d26e0 100644 --- a/src/Menu/AdminMenuListener.php +++ b/src/Menu/AdminMenuListener.php @@ -19,17 +19,11 @@ final class AdminMenuListener { - private MenuManipulator $manipulator; - - private RegistryInterface $settingsRegistry; - /** * AdminMenuListener constructor. */ - public function __construct(MenuManipulator $manipulator, RegistryInterface $settingsRegistry) + public function __construct(private MenuManipulator $manipulator, private RegistryInterface $settingsRegistry) { - $this->manipulator = $manipulator; - $this->settingsRegistry = $settingsRegistry; } public function addAdminMenuItems(MenuBuilderEvent $event): void diff --git a/src/Menu/SettingsFormMenuBuilder.php b/src/Menu/SettingsFormMenuBuilder.php index 63547a73..3660567a 100644 --- a/src/Menu/SettingsFormMenuBuilder.php +++ b/src/Menu/SettingsFormMenuBuilder.php @@ -22,23 +22,14 @@ final class SettingsFormMenuBuilder { - private FactoryInterface $factory; - - private ChannelRepositoryInterface $channelRepository; - - private RepositoryInterface $localeRepository; - /** * SettingsFormMenuBuilder constructor. */ public function __construct( - FactoryInterface $factory, - ChannelRepositoryInterface $channelRepository, - RepositoryInterface $localeRepository + private FactoryInterface $factory, + private ChannelRepositoryInterface $channelRepository, + private RepositoryInterface $localeRepository ) { - $this->factory = $factory; - $this->channelRepository = $channelRepository; - $this->localeRepository = $localeRepository; } public function createMenu(array $options = []): ItemInterface diff --git a/src/Processor/SettingsProcessor.php b/src/Processor/SettingsProcessor.php index 2250c1d0..b07d2810 100644 --- a/src/Processor/SettingsProcessor.php +++ b/src/Processor/SettingsProcessor.php @@ -26,27 +26,15 @@ final class SettingsProcessor implements SettingsProcessorInterface { - private ChannelRepositoryInterface $channelRepository; - - private RepositoryInterface $localeRepository; - - private EntityManagerInterface $entityManager; - - private SettingFactoryInterface $settingFactory; - /** * SettingsProcessor constructor. */ public function __construct( - ChannelRepositoryInterface $channelRepository, - RepositoryInterface $localeRepository, - EntityManagerInterface $entityManager, - SettingFactoryInterface $settingFactory + private ChannelRepositoryInterface $channelRepository, + private RepositoryInterface $localeRepository, + private EntityManagerInterface $entityManager, + private SettingFactoryInterface $settingFactory ) { - $this->channelRepository = $channelRepository; - $this->localeRepository = $localeRepository; - $this->entityManager = $entityManager; - $this->settingFactory = $settingFactory; } public function processData(SettingsInterface $settings, array $data): void diff --git a/src/Provider/SettingsProvider.php b/src/Provider/SettingsProvider.php index 6564a748..47a2eeca 100644 --- a/src/Provider/SettingsProvider.php +++ b/src/Provider/SettingsProvider.php @@ -21,28 +21,17 @@ class SettingsProvider implements SettingsProviderInterface { - private RegistryInterface $settingsRegistry; - - private LocaleContextInterface $localeContext; - - private ChannelContextInterface $channelContext; - public function __construct( - RegistryInterface $settingsRegistry, - ChannelContextInterface $channelContext, - LocaleContextInterface $localeContext + private RegistryInterface $settingsRegistry, + private ChannelContextInterface $channelContext, + private LocaleContextInterface $localeContext ) { - $this->settingsRegistry = $settingsRegistry; - $this->channelContext = $channelContext; - $this->localeContext = $localeContext; } /** * @throws SettingsException - * - * @return mixed */ - public function getSettingValue(string $alias, string $path) + public function getSettingValue(string $alias, string $path): mixed { return $this->getSettingValueByChannelAndLocale( $alias, @@ -54,15 +43,13 @@ public function getSettingValue(string $alias, string $path) /** * @throws SettingsException - * - * @return mixed */ public function getSettingValueByChannelAndLocale( string $alias, string $path, ChannelInterface $channel, ?string $locale = null - ) { + ): mixed { if ($settingsInstance = $this->settingsRegistry->getByAlias($alias)) { return $settingsInstance->getCurrentValue($channel, $locale, $path); } diff --git a/src/Provider/SettingsProviderInterface.php b/src/Provider/SettingsProviderInterface.php index 9cace9bb..c475da6f 100644 --- a/src/Provider/SettingsProviderInterface.php +++ b/src/Provider/SettingsProviderInterface.php @@ -17,18 +17,12 @@ interface SettingsProviderInterface { - /** - * @return mixed - */ - public function getSettingValue(string $alias, string $path); + public function getSettingValue(string $alias, string $path): mixed; - /** - * @return mixed - */ public function getSettingValueByChannelAndLocale( string $alias, string $path, ChannelInterface $channel, ?string $locale = null - ); + ): mixed; } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index b18a5153..4037b353 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -11,24 +11,10 @@ services: autowire: false Sylius\Component\Resource\Model\ResourceInterface: autowire: false - - MonsieurBiz\SyliusSettingsPlugin\Controller\: - resource: '../../Controller' - tags: ['controller.service_arguments'] - - MonsieurBiz\SyliusSettingsPlugin\Form\: - resource: '../../Form' - tags: ['form.type'] - - MonsieurBiz\SyliusSettingsPlugin\Processor\: - resource: '../../Processor' - - MonsieurBiz\SyliusSettingsPlugin\Factory\Form\: - resource: '../../Factory/Form' - - MonsieurBiz\SyliusSettingsPlugin\Twig\Extension\: - resource: '../../Twig/Extension' - tags: ['twig.extension'] + + MonsieurBiz\SyliusSettingsPlugin\: + resource: '../../*' + exclude: '../../{Entity,Migrations}' MonsieurBiz\SyliusSettingsPlugin\Menu\AdminMenuListener: tags: @@ -52,17 +38,3 @@ services: class: MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProvider MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProviderInterface: '@monsieurbiz.settings.provider' - - monsieurbiz.setting.provider: - class: MonsieurBiz\SyliusSettingsPlugin\Provider\SettingProvider - - MonsieurBiz\SyliusSettingsPlugin\Provider\SettingProviderInterface: '@monsieurbiz.setting.provider' - - MonsieurBiz\SyliusSettingsPlugin\Fixture\: - resource: '../../Fixture' - - MonsieurBiz\SyliusSettingsPlugin\Command\: - resource: '../../Command' - - MonsieurBiz\SyliusSettingsPlugin\Formatter\: - resource: '../../Formatter' diff --git a/src/Settings/Metadata.php b/src/Settings/Metadata.php index 489710ac..854a9b45 100644 --- a/src/Settings/Metadata.php +++ b/src/Settings/Metadata.php @@ -68,10 +68,7 @@ public function getName(bool $aliased = false): string return $aliased ? $this->alias($this->name) : $this->name; } - /** - * @inheritdoc - */ - public function getParameter(string $name) + 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())); @@ -80,17 +77,11 @@ public function getParameter(string $name) return $this->parameters[$name]; } - /** - * @inheritdoc - */ public function hasParameter(string $name): bool { return \array_key_exists($name, $this->parameters); } - /** - * @inheritdoc - */ public function getParameters(): array { return $this->parameters; @@ -101,9 +92,6 @@ public function getDefaultValues(): array return $this->parameters['default_values']; } - /** - * @inheritdoc - */ public function getClass(string $name): string { if (!$this->hasClass($name)) { @@ -113,17 +101,11 @@ public function getClass(string $name): string return $this->parameters['classes'][$name]; } - /** - * @inheritdoc - */ public function hasClass(string $name): bool { return isset($this->parameters['classes'][$name]); } - /** - * @inheritdoc - */ public function getServiceId(string $serviceName): string { return sprintf('%s.%s.%s', $this->applicationName, $serviceName, $this->alias($this->name)); @@ -131,7 +113,7 @@ public function getServiceId(string $serviceName): string private static function parseAlias(string $alias): array { - if (false === strpos($alias, '.')) { + if (!str_contains($alias, '.')) { throw new InvalidArgumentException(sprintf('Invalid alias "%s" supplied, it should conform to the following format ".".', $alias)); } @@ -143,9 +125,6 @@ private static function alias(string $string): string return strtolower(preg_replace('`([A-Z])`', '_\1', lcfirst($string)) ?? ''); } - /** - * @inheritdoc - */ public function useLocales(): bool { if (!$this->hasParameter('use_locales')) { diff --git a/src/Settings/MetadataInterface.php b/src/Settings/MetadataInterface.php index e3f22528..fd0516df 100644 --- a/src/Settings/MetadataInterface.php +++ b/src/Settings/MetadataInterface.php @@ -29,10 +29,7 @@ public function getApplicationName(bool $aliased = false): string; */ public function getName(bool $aliased = false): string; - /** - * @return mixed - */ - public function getParameter(string $name); + public function getParameter(string $name): mixed; public function hasParameter(string $name): bool; diff --git a/src/Settings/Settings.php b/src/Settings/Settings.php index f61c9ee0..adb6adc2 100644 --- a/src/Settings/Settings.php +++ b/src/Settings/Settings.php @@ -23,10 +23,6 @@ final class Settings implements SettingsInterface { public const DEFAULT_KEY = 'default'; - private Metadata $metadata; - - private SettingRepositoryInterface $settingRepository; - private ?array $settingsByChannelAndLocale; private ?array $settingsByChannelAndLocaleWithDefault; @@ -34,10 +30,8 @@ final class Settings implements SettingsInterface /** * Settings constructor. */ - public function __construct(Metadata $metadata, SettingRepositoryInterface $settingRepository) + public function __construct(private Metadata $metadata, private SettingRepositoryInterface $settingRepository) { - $this->metadata = $metadata; - $this->settingRepository = $settingRepository; } public function getAlias(): string @@ -197,7 +191,7 @@ public function getSettingsValuesByChannelAndLocale(?ChannelInterface $channel = return $settingsValues; } - public function getCurrentValue(?ChannelInterface $channel, ?string $localeCode, string $path) + public function getCurrentValue(?ChannelInterface $channel, ?string $localeCode, string $path): mixed { $settings = $this->getSettingsByChannelAndLocale($channel, $localeCode, true); if (isset($settings[$path])) { @@ -212,7 +206,7 @@ public function getDefaultValues(): array return $this->metadata->getDefaultValues(); } - public function getDefaultValue(string $path) + public function getDefaultValue(string $path): mixed { $defaultValues = $this->getDefaultValues(); if (\array_key_exists($path, $defaultValues)) { diff --git a/src/Settings/SettingsInterface.php b/src/Settings/SettingsInterface.php index 8af9509b..f29562b8 100644 --- a/src/Settings/SettingsInterface.php +++ b/src/Settings/SettingsInterface.php @@ -47,17 +47,11 @@ public function getSettingsByChannelAndLocale(?ChannelInterface $channel = null, public function getSettingsValuesByChannelAndLocale(?ChannelInterface $channel = null, ?string $localeCode = null): array; - /** - * @return mixed - */ - public function getCurrentValue(?ChannelInterface $channel, ?string $localeCode, string $path); + public function getCurrentValue(?ChannelInterface $channel, ?string $localeCode, string $path): mixed; public function getDefaultValues(): array; - /** - * @return mixed - */ - public function getDefaultValue(string $path); + public function getDefaultValue(string $path): mixed; public function showLocalesInForm(): bool; } diff --git a/src/Twig/Extension/SettingsExtension.php b/src/Twig/Extension/SettingsExtension.php index 986dde1d..fb745aec 100644 --- a/src/Twig/Extension/SettingsExtension.php +++ b/src/Twig/Extension/SettingsExtension.php @@ -22,14 +22,11 @@ final class SettingsExtension extends AbstractExtension implements ExtensionInterface { - private SettingsProviderInterface $settingsProvider; - - public function __construct(SettingsProviderInterface $settings) + public function __construct(private SettingsProviderInterface $settingsProvider) { - $this->settingsProvider = $settings; } - public function getFunctions() + public function getFunctions(): array { return [ new TwigFunction('setting', [$this, 'getSettingValue'], [ @@ -38,10 +35,7 @@ public function getFunctions() ]; } - /** - * @return mixed - */ - public function getSettingValue(array $context, string $alias, string $path) + public function getSettingValue(array $context, string $alias, string $path): mixed { if (isset($context['sylius']) && $context['sylius'] instanceof ShopperContextInterface) { try {