apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -23,8 +23,6 @@ use Chill\MainBundle\Controller\RegroupmentController;
use Chill\MainBundle\Controller\UserController;
use Chill\MainBundle\Controller\UserJobApiController;
use Chill\MainBundle\Controller\UserJobController;
use Chill\MainBundle\Controller\UserJobHistoryController;
use Chill\MainBundle\Controller\UserScopeHistoryController;
use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
use Chill\MainBundle\Doctrine\DQL\Age;
use Chill\MainBundle\Doctrine\DQL\Extract;
@@ -59,8 +57,6 @@ use Chill\MainBundle\Entity\Regroupment;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Form\CenterType;
use Chill\MainBundle\Entity\User\UserJobHistory;
use Chill\MainBundle\Entity\User\UserScopeHistory;
use Chill\MainBundle\Form\CivilityType;
use Chill\MainBundle\Form\CountryType;
use Chill\MainBundle\Form\LanguageType;
@@ -69,7 +65,6 @@ use Chill\MainBundle\Form\LocationTypeType;
use Chill\MainBundle\Form\RegroupmentType;
use Chill\MainBundle\Form\UserJobType;
use Chill\MainBundle\Form\UserType;
use Exception;
use Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType;
use Ramsey\Uuid\Doctrine\UuidType;
use Symfony\Component\Config\FileLocator;
@@ -79,8 +74,6 @@ use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use function count;
/**
* Class ChillMainExtension
* This class load config for chillMainExtension.
@@ -101,7 +94,7 @@ class ChillMainExtension extends Extension implements
$this->widgetFactories[] = $factory;
}
public function getConfiguration(array $config, ContainerBuilder $container): \Chill\MainBundle\DependencyInjection\Configuration
public function getConfiguration(array $config, ContainerBuilder $container): Configuration
{
return new Configuration($this->widgetFactories, $container);
}
@@ -115,7 +108,7 @@ class ChillMainExtension extends Extension implements
}
/**
* @throws Exception
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
{
@@ -195,7 +188,7 @@ class ChillMainExtension extends Extension implements
[]
);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader->load('services.yaml');
$loader->load('services/doctrine.yaml');
$loader->load('services/logger.yaml');
@@ -223,12 +216,12 @@ class ChillMainExtension extends Extension implements
$this->configureCruds($container, $config['cruds'], $config['apis'], $loader);
$container->setParameter('chill_main.short_messages', $config['short_messages']);
//$this->configureSms($config['short_messages'], $container, $loader);
// $this->configureSms($config['short_messages'], $container, $loader);
}
public function prepend(ContainerBuilder $container)
{
//add installation_name and date_format to globals
// add installation_name and date_format to globals
$chillMainConfig = $container->getExtensionConfig($this->getAlias());
$config = $this->processConfiguration($this
->getConfiguration($chillMainConfig, $container), $chillMainConfig);
@@ -243,7 +236,7 @@ class ChillMainExtension extends Extension implements
];
$container->prependExtensionConfig('twig', $twigConfig);
//add DQL function to ORM (default entity_manager)
// add DQL function to ORM (default entity_manager)
$container
->prependExtensionConfig(
'doctrine',
@@ -283,7 +276,7 @@ class ChillMainExtension extends Extension implements
],
);
//add dbal types (default entity_manager)
// add dbal types (default entity_manager)
$container
->prependExtensionConfig(
'doctrine',
@@ -305,7 +298,7 @@ class ChillMainExtension extends Extension implements
]
);
//add current route to chill main
// add current route to chill main
$container->prependExtensionConfig('chill_main', [
'routing' => [
'resources' => [
@@ -314,7 +307,7 @@ class ChillMainExtension extends Extension implements
],
]);
//add a channel to log app events
// add a channel to log app events
$container->prependExtensionConfig('monolog', [
'channels' => ['chill'],
]);
@@ -326,7 +319,7 @@ class ChillMainExtension extends Extension implements
],
]);
//add crud api
// add crud api
$this->prependCruds($container);
}
@@ -339,7 +332,7 @@ class ChillMainExtension extends Extension implements
array $apiConfig,
Loader\YamlFileLoader $loader
): void {
if (count($crudConfig) === 0) {
if (0 === \count($crudConfig)) {
return;
}
@@ -773,7 +766,7 @@ class ChillMainExtension extends Extension implements
],
],
],
]
],
],
]);
}

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
use Chill\MainBundle\Form\PermissionsGroupType;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -29,13 +28,7 @@ class ACLFlagsCompilerPass implements CompilerPassInterface
foreach ($tags as $tag) {
match ($tag['scope']) {
PermissionsGroupType::FLAG_SCOPE => $permissionGroupType->addMethodCall('addFlagProvider', [$reference]),
default => throw new LogicException(
sprintf(
"This tag 'scope' is not implemented: %s, on service with id %s",
$tag['scope'],
$id
)
),
default => throw new \LogicException(sprintf("This tag 'scope' is not implemented: %s, on service with id %s", $tag['scope'], $id)),
};
}
}

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
use Chill\MainBundle\Export\ExportManager;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
@@ -32,8 +31,7 @@ class ExportsCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
if (!$container->has(ExportManager::class)) {
throw new LogicException('service ' . ExportManager::class . ' '
. 'is not defined. It is required by ExportsCompilerPass');
throw new \LogicException('service '.ExportManager::class.' is not defined. It is required by ExportsCompilerPass');
}
$chillManagerDefinition = $container->findDefinition(
@@ -57,13 +55,11 @@ class ExportsCompilerPass implements CompilerPassInterface
foreach ($taggedServices as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
if (!isset($attributes['prefix'])) {
throw new LogicException("the 'prefix' attribute is missing in your " .
"service '{$id}' definition");
throw new \LogicException("the 'prefix' attribute is missing in your service '{$id}' definition");
}
if (array_search($attributes['prefix'], $knownAliases, true)) {
throw new LogicException('There is already a chill.export_elements_provider service with prefix '
. $attributes['prefix'] . '. Choose another prefix.');
throw new \LogicException('There is already a chill.export_elements_provider service with prefix '.$attributes['prefix'].'. Choose another prefix.');
}
$knownAliases[] = $attributes['prefix'];
@@ -88,13 +84,11 @@ class ExportsCompilerPass implements CompilerPassInterface
foreach ($taggedServices as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
if (!isset($attributes['alias'])) {
throw new LogicException("the 'alias' attribute is missing in your " .
"service '{$id}' definition");
throw new \LogicException("the 'alias' attribute is missing in your service '{$id}' definition");
}
if (array_search($attributes['alias'], $knownAliases, true)) {
throw new LogicException('There is already a chill.export_formatter service with alias '
. $attributes['alias'] . '. Choose another alias.');
throw new \LogicException('There is already a chill.export_formatter service with alias '.$attributes['alias'].'. Choose another alias.');
}
$knownAliases[] = $attributes['alias'];

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
use Chill\MainBundle\Routing\MenuComposer;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -22,8 +21,7 @@ class MenuCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('chill.main.menu_composer')) {
throw new LogicException(sprintf('The service %s does not exists in '
. 'container.', MenuComposer::class));
throw new \LogicException(sprintf('The service %s does not exists in container.', MenuComposer::class));
}
$menuComposerDefinition = $container->getDefinition('chill.main.menu_composer');

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
use Chill\MainBundle\Templating\UI\CountNotificationUser;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -22,8 +21,7 @@ class NotificationCounterCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(CountNotificationUser::class)) {
throw new LogicException('The service ' . CountNotificationUser::class . ' '
. 'should be defined');
throw new \LogicException('The service '.CountNotificationUser::class.' should be defined');
}
$notificationCounterDefinition = $container->getDefinition(CountNotificationUser::class);

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -26,8 +25,7 @@ class SearchableServicesCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('chill_main.search_provider')) {
throw new LogicException('service chill_main.search_provider '
. 'is not defined.');
throw new \LogicException('service chill_main.search_provider is not defined.');
}
$definition = $container->getDefinition(
@@ -43,13 +41,11 @@ class SearchableServicesCompilerPass implements CompilerPassInterface
foreach ($taggedServices as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
if (!isset($attributes['alias'])) {
throw new LogicException("the 'name' attribute is missing in your " .
"service '{$id}' definition");
throw new \LogicException("the 'name' attribute is missing in your service '{$id}' definition");
}
if (array_search($attributes['alias'], $knownAliases, true)) {
throw new LogicException('There is already a chill.search service with alias '
. $attributes['alias'] . '. Choose another alias.');
throw new \LogicException('There is already a chill.search service with alias '.$attributes['alias'].'. Choose another alias.');
}
$knownAliases[] = $attributes['alias'];

View File

@@ -28,7 +28,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Reference;
use function array_key_exists;
class ShortMessageCompilerPass implements CompilerPassInterface
{
@@ -43,30 +42,28 @@ class ShortMessageCompilerPass implements CompilerPassInterface
if ('null' === $dsn['scheme'] || false === $config['enabled']) {
$defaultTransporter = new Reference(NullShortMessageSender::class);
} elseif ('ovh' === $dsn['scheme']) {
if (!class_exists('\\' . \Ovh\Api::class)) {
if (!class_exists('\\'.\Ovh\Api::class)) {
throw new RuntimeException('Class \\Ovh\\Api not found');
}
foreach (['user', 'host', 'pass'] as $component) {
if (!array_key_exists($component, $dsn)) {
throw new RuntimeException(sprintf('The component %s does not exist in dsn. Please provide a dsn ' .
'like ovh://applicationKey:applicationSecret@endpoint?consumerKey=xxxx&sender=yyyy&service_name=zzzz', $component));
if (!\array_key_exists($component, $dsn)) {
throw new RuntimeException(sprintf('The component %s does not exist in dsn. Please provide a dsn like ovh://applicationKey:applicationSecret@endpoint?consumerKey=xxxx&sender=yyyy&service_name=zzzz', $component));
}
$container->setParameter('chill_main.short_messages.ovh_config_' . $component, $dsn[$component]);
$container->setParameter('chill_main.short_messages.ovh_config_'.$component, $dsn[$component]);
}
foreach (['consumer_key', 'sender', 'service_name'] as $param) {
if (!array_key_exists($param, $dsn['queries'])) {
throw new RuntimeException(sprintf('The parameter %s does not exist in dsn. Please provide a dsn ' .
'like ovh://applicationKey:applicationSecret@endpoint?consumerKey=xxxx&sender=yyyy&service_name=zzzz', $param));
if (!\array_key_exists($param, $dsn['queries'])) {
throw new RuntimeException(sprintf('The parameter %s does not exist in dsn. Please provide a dsn like ovh://applicationKey:applicationSecret@endpoint?consumerKey=xxxx&sender=yyyy&service_name=zzzz', $param));
}
$container->setParameter('chill_main.short_messages.ovh_config_' . $param, $dsn['queries'][$param]);
$container->setParameter('chill_main.short_messages.ovh_config_'.$param, $dsn['queries'][$param]);
}
$ovh = new Definition();
$ovh
->setClass('\\' . \Ovh\Api::class)
->setClass('\\'.\Ovh\Api::class)
->setArgument(0, $dsn['user'])
->setArgument(1, $dsn['pass'])
->setArgument(2, $dsn['host'])

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -25,8 +24,7 @@ class TimelineCompilerClass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('chill_main.timeline_builder')) {
throw new LogicException('service chill_main.timeline_builder '
. 'is not defined.');
throw new \LogicException('service chill_main.timeline_builder is not defined.');
}
$definition = $container->getDefinition(
@@ -40,8 +38,7 @@ class TimelineCompilerClass implements CompilerPassInterface
foreach ($taggedServices as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
if (!isset($attributes['context'])) {
throw new LogicException("the 'context' attribute is missing in your " .
"service '{$id}' definition");
throw new \LogicException("the 'context' attribute is missing in your service '{$id}' definition");
}
$definition->addMethodCall(

View File

@@ -11,13 +11,9 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection;
use LogicException;
use RuntimeException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use function count;
/**
* Description of ConfigConsistencyCompilerPass.
*/
@@ -42,17 +38,14 @@ class ConfigConsistencyCompilerPass implements CompilerPassInterface
}
}
if (count($fallbackLocales) === 0) {
throw new LogicException('the fallback locale are not defined. '
. 'The framework config should not allow this.');
if (0 === \count($fallbackLocales)) {
throw new \LogicException('the fallback locale are not defined. The framework config should not allow this.');
}
$diff = array_diff($fallbackLocales, $availableLanguages);
if (count($diff) > 0) {
throw new RuntimeException(sprintf('The chill_main.available_languages'
. ' parameter does not contains fallback locales. The languages %s'
. ' are missing.', implode(', ', $diff)));
if (\count($diff) > 0) {
throw new \RuntimeException(sprintf('The chill_main.available_languages parameter does not contains fallback locales. The languages %s are missing.', implode(', ', $diff)));
}
}
}

View File

@@ -176,8 +176,8 @@ class Configuration implements ConfigurationInterface
->scalarNode('path')
->defaultNull()
->info('the path that will be **appended** after the base path. Do not forget to add '
. 'arguments for the method. Will be set to the action name, including an `{id}` '
. 'parameter if left empty.')
.'arguments for the method. Will be set to the action name, including an `{id}` '
.'parameter if left empty.')
->example('/{id}/my-action')
->end()
->arrayNode('requirements')
@@ -216,15 +216,15 @@ class Configuration implements ConfigurationInterface
->children()
->scalarNode('controller_action')
->defaultNull()
->info('the method name to call in the controller. Will be set to the concatenation ' .
->info('the method name to call in the controller. Will be set to the concatenation '.
'of action name + \'Api\' if left empty.')
->example('showApi')
->end()
->scalarNode('path')
->defaultNull()
->info('the path that will be **appended** after the base path. Do not forget to add ' .
'arguments for the method. By default, will set to the action name, including an `{id}` ' .
'parameter. A suffix of action name will be appended, except if the action name ' .
->info('the path that will be **appended** after the base path. Do not forget to add '.
'arguments for the method. By default, will set to the action name, including an `{id}` '.
'parameter. A suffix of action name will be appended, except if the action name '.
'is "_entity".')
->example('/{id}/my-action')
->end()
@@ -235,8 +235,8 @@ class Configuration implements ConfigurationInterface
->enumNode('single_collection')
->values(['single', 'collection'])
->defaultValue('single')
->info('indicates if the returned object is a single element or a collection. ' .
'If the action name is `_index`, this value will always be considered as ' .
->info('indicates if the returned object is a single element or a collection. '.
'If the action name is `_index`, this value will always be considered as '.
'`collection`')
->end()
->arrayNode('methods')

View File

@@ -11,12 +11,10 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection;
use Exception;
/**
* Description of MissingBundleException.
*/
class MissingBundleException extends Exception
class MissingBundleException extends \Exception
{
public function __construct($missingBundleName)
{

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -21,8 +20,7 @@ class RoleProvidersCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('chill.main.role_provider')) {
throw new LogicException('service chill.main.role_provider '
. 'is not defined. It is required by RoleProviderCompilerPass');
throw new \LogicException('service chill.main.role_provider is not defined. It is required by RoleProviderCompilerPass');
}
$definition = $container->getDefinition(

View File

@@ -13,20 +13,11 @@ namespace Chill\MainBundle\DependencyInjection\Widget;
use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
use Doctrine\Common\Proxy\Exception\InvalidArgumentException;
use LengthException;
use LogicException;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use UnexpectedValueException;
use function array_key_exists;
use function count;
use function get_class;
use function in_array;
use function is_array;
/**
* Compile the configurations and inject required service into container.
@@ -122,11 +113,11 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
/**
* process the configuration and the container to add the widget available.
*
* @param string $extension the extension of your bundle
* @param string $extension the extension of your bundle
* @param string $containerWidgetConfigParameterName the key under which we can use the widget configuration
*
* @throws LogicException
* @throws UnexpectedValueException if the given extension does not implement HasWidgetExtensionInterface
* @throws \LogicException
* @throws \UnexpectedValueException if the given extension does not implement HasWidgetExtensionInterface
*/
public function doProcess(
ContainerBuilder $container,
@@ -134,8 +125,7 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
$containerWidgetConfigParameterName
) {
if (!$container->hasDefinition(self::WIDGET_MANAGER)) {
throw new LogicException('the service ' . self::WIDGET_MANAGER . ' should' .
' be present. It is required by ' . self::class);
throw new \LogicException('the service '.self::WIDGET_MANAGER.' should be present. It is required by '.self::class);
}
$managerDefinition = $container->getDefinition(self::WIDGET_MANAGER);
@@ -145,14 +135,7 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
$extensionClass = $container->getExtension($extension);
// throw an error if extension does not implement HasWidgetFactoriesExtensionInterface
if (!$extensionClass instanceof HasWidgetFactoriesExtensionInterface) {
throw new UnexpectedValueException(sprintf(
'The extension for %s '
. 'do not implements %s. You should implement %s on %s',
$extension,
HasWidgetFactoriesExtensionInterface::class,
HasWidgetFactoriesExtensionInterface::class,
$extensionClass::class
));
throw new \UnexpectedValueException(sprintf('The extension for %s do not implements %s. You should implement %s on %s', $extension, HasWidgetFactoriesExtensionInterface::class, HasWidgetFactoriesExtensionInterface::class, $extensionClass::class));
}
$this->widgetFactories = $extensionClass->getWidgetFactories();
@@ -168,18 +151,13 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
foreach ($widgets as $param) {
$alias = $param[self::WIDGET_CONFIG_ALIAS];
// check that the service exists
if (!array_key_exists($alias, $this->widgetServices)) {
throw new InvalidConfigurationException(sprintf('The alias %s' .
' is not defined.', $alias));
if (!\array_key_exists($alias, $this->widgetServices)) {
throw new InvalidConfigurationException(sprintf('The alias %s is not defined.', $alias));
}
// check that the widget is allowed at this place
if (!$this->isPlaceAllowedForWidget($place, $alias, $container)) {
throw new InvalidConfigurationException(sprintf(
'The widget with alias %s is not allowed at place %s',
$alias,
$place
));
throw new InvalidConfigurationException(sprintf('The widget with alias %s is not allowed at place %s', $alias, $place));
}
// get the order, eventually corrected
@@ -242,23 +220,17 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
foreach ($attrs as $attr) {
// check the alias is set
if (!isset($attr[self::WIDGET_SERVICE_TAG_ALIAS])) {
throw new InvalidConfigurationException('you should add an ' . self::WIDGET_SERVICE_TAG_ALIAS .
' key on the service ' . $id);
throw new InvalidConfigurationException('you should add an '.self::WIDGET_SERVICE_TAG_ALIAS.' key on the service '.$id);
}
// check the place is set
if (!isset($attr[self::WIDGET_SERVICE_TAG_PLACES])) {
throw new InvalidConfigurationException(sprintf(
'You should add a %s key on the service %s',
self::WIDGET_SERVICE_TAG_PLACES,
$id
));
throw new InvalidConfigurationException(sprintf('You should add a %s key on the service %s', self::WIDGET_SERVICE_TAG_PLACES, $id));
}
// check the alias does not exists yet
if (array_key_exists($attr[self::WIDGET_SERVICE_TAG_ALIAS], $this->widgetServices)) {
throw new InvalidArgumentException('a service has already be defined with the ' .
self::WIDGET_SERVICE_TAG_ALIAS . ' ' . $attr[self::WIDGET_SERVICE_TAG_ALIAS]);
if (\array_key_exists($attr[self::WIDGET_SERVICE_TAG_ALIAS], $this->widgetServices)) {
throw new InvalidArgumentException('a service has already be defined with the '.self::WIDGET_SERVICE_TAG_ALIAS.' '.$attr[self::WIDGET_SERVICE_TAG_ALIAS]);
}
// register the service as available
@@ -273,29 +245,21 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
// check the alias is not empty
if (empty($alias)) {
throw new LogicException(sprintf(
'the widget factory %s returns an empty alias',
$factory::class
));
throw new \LogicException(sprintf('the widget factory %s returns an empty alias', $factory::class));
}
// check the places are not empty
if (!is_array($factory->getAllowedPlaces())) {
throw new UnexpectedValueException("the method 'getAllowedPlaces' "
. 'should return a non-empty array. Unexpected value on ' .
$factory::class);
if (!\is_array($factory->getAllowedPlaces())) {
throw new \UnexpectedValueException("the method 'getAllowedPlaces' ".'should return a non-empty array. Unexpected value on '.$factory::class);
}
if (count($factory->getAllowedPlaces()) === 0) {
throw new LengthException("The method 'getAllowedPlaces' should "
. 'return a non-empty array, but returned 0 elements on ' .
$factory::class . '::getAllowedPlaces()');
if (0 === \count($factory->getAllowedPlaces())) {
throw new \LengthException("The method 'getAllowedPlaces' should ".'return a non-empty array, but returned 0 elements on '.$factory::class.'::getAllowedPlaces()');
}
// check the alias does not exists yet
if (array_key_exists($alias, $this->widgetServices)) {
throw new InvalidArgumentException('a service has already be defined with the ' .
self::WIDGET_SERVICE_TAG_ALIAS . ' ' . $alias);
if (\array_key_exists($alias, $this->widgetServices)) {
throw new InvalidArgumentException('a service has already be defined with the '.self::WIDGET_SERVICE_TAG_ALIAS.' '.$alias);
}
// register the factory as available
@@ -307,7 +271,7 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
* register the service into container.
*
* @param string $place
* @param float $order
* @param float $order
*
* @return string the id of the new service
*/
@@ -338,14 +302,14 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
* recursive method.
*
* @param string $place
* @param float $ordering
* @param float $ordering
*
* @return float
*/
private function cacheAndGetOrdering($place, $ordering)
{
// create a key in the cache array if not exists
if (!array_key_exists($place, $this->cacheOrdering)) {
if (!\array_key_exists($place, $this->cacheOrdering)) {
$this->cacheOrdering[$place] = [];
}
@@ -363,14 +327,13 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
/**
* get the places where the service is allowed.
*
*
* @return unknown
*/
private function isPlaceAllowedForWidget(mixed $place, mixed $widgetAlias, ContainerBuilder $container)
{
if ($this->widgetServices[$widgetAlias] instanceof WidgetFactoryInterface) {
if (
in_array($place, $this->widgetServices[$widgetAlias]
\in_array($place, $this->widgetServices[$widgetAlias]
->getAllowedPlaces(), true)
) {
return true;

View File

@@ -16,10 +16,6 @@ use Generator;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use function array_key_exists;
use function count;
use function implode;
use function in_array;
/**
* This trait allow to add automatic configuration for widget inside your config.
@@ -141,10 +137,10 @@ trait AddWidgetConfigurationTrait
$treeBuilder = new TreeBuilder($place);
$root = $treeBuilder->getRootNode()
->canBeUnset()
->info('register widgets on place "' . $place . '"');
->info('register widgets on place "'.$place.'"');
// if no childen, return the root
if (count(iterator_to_array($this->filterWidgetByPlace($place))) === 0) {
if (0 === \count(iterator_to_array($this->filterWidgetByPlace($place)))) {
return $root;
}
@@ -162,8 +158,8 @@ trait AddWidgetConfigurationTrait
// is build, the services are avaialble => we add the possible aliases
// in the info.
->info('the widget alias (see your installed bundles config). '
. 'Possible values are (maybe incomplete) : ' .
implode(', ', $this->getWidgetAliasesbyPlace($place, $containerBuilder)))
.'Possible values are (maybe incomplete) : '.
\implode(', ', $this->getWidgetAliasesbyPlace($place, $containerBuilder)))
->isRequired()
->end();
@@ -188,12 +184,12 @@ trait AddWidgetConfigurationTrait
*
* @param string $place
*
* @return Generator a generator containing a widget factory
* @return \Generator a generator containing a widget factory
*/
protected function filterWidgetByPlace($place)
{
foreach ($this->widgetFactories as $factory) {
if (in_array($place, $factory->getAllowedPlaces(), true)) {
if (\in_array($place, $factory->getAllowedPlaces(), true)) {
yield $factory;
}
}
@@ -209,9 +205,9 @@ trait AddWidgetConfigurationTrait
*
* @param type $place
*
* @throws InvalidConfigurationException if a service's tag does not have the "alias" key
*
* @return array
*
* @throws InvalidConfigurationException if a service's tag does not have the "alias" key
*/
protected function getWidgetAliasesbyPlace($place, ContainerBuilder $containerBuilder)
{
@@ -223,16 +219,11 @@ trait AddWidgetConfigurationTrait
// append the aliases added without factory
foreach ($containerBuilder
->findTaggedServiceIds(WidgetsCompilerPass::WIDGET_SERVICE_TAG_NAME)
as $serviceId => $tags) {
->findTaggedServiceIds(WidgetsCompilerPass::WIDGET_SERVICE_TAG_NAME) as $serviceId => $tags) {
foreach ($tags as $tag) {
// throw an error if no alias in definition
if (!array_key_exists(WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS, $tag)) {
throw new InvalidConfigurationException(sprintf(
'The service with id %s does not have any %d key',
$serviceId,
WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS
));
if (!\array_key_exists(WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS, $tag)) {
throw new InvalidConfigurationException(sprintf('The service with id %s does not have any %d key', $serviceId, WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS));
}
// add the key to the possible results
$result[] = $tag[WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS];

View File

@@ -72,7 +72,7 @@ interface WidgetFactoryInterface
* return the service id to build the widget.
*
* @param string $place
* @param float $order
* @param float $order
*
* @return string the service definition
*/