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/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 4aa18bab..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): mixed + 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/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 {