Skip to content

Commit

Permalink
refactor(php8+): Update __construct methods + add return type mixed +…
Browse files Browse the repository at this point in the history
… add missing return types + remove useless phpdoc
  • Loading branch information
etienne-monsieurbiz committed Jul 25, 2023
1 parent cc83e95 commit d879566
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 169 deletions.
20 changes: 4 additions & 16 deletions src/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 3 additions & 12 deletions src/Factory/Form/MainSettingsFormTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions src/Factory/SettingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 2 additions & 8 deletions src/Form/MainSettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Formatter/SettingsFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions src/Formatter/SettingsFormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 1 addition & 7 deletions src/Menu/AdminMenuListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 3 additions & 12 deletions src/Menu/SettingsFormMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 4 additions & 16 deletions src/Processor/SettingsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions src/Provider/SettingsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
10 changes: 2 additions & 8 deletions src/Provider/SettingsProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
25 changes: 2 additions & 23 deletions src/Settings/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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;
Expand All @@ -101,9 +92,6 @@ public function getDefaultValues(): array
return $this->parameters['default_values'];
}

/**
* @inheritdoc
*/
public function getClass(string $name): string
{
if (!$this->hasClass($name)) {
Expand All @@ -113,25 +101,19 @@ 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));
}

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 "<applicationName>.<name>".', $alias));
}

Expand All @@ -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')) {
Expand Down
5 changes: 1 addition & 4 deletions src/Settings/MetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit d879566

Please sign in to comment.