mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -15,19 +15,12 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Templating\Widget\WidgetInterface;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use DateTime;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Twig\Environment;
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* add a widget with person list.
|
||||
@@ -43,9 +36,6 @@ class PersonListWidget implements WidgetInterface
|
||||
|
||||
public function __construct(protected PersonRepository $personRepository, protected EntityManagerInterface $entityManager, protected AuthorizationHelperInterface $authorizationHelper, protected TokenStorageInterface $tokenStorage) {}
|
||||
|
||||
/**
|
||||
* @param mixed $place
|
||||
*/
|
||||
public function render(Environment $env, $place, array $context, array $config)
|
||||
{
|
||||
$numberOfItems = $config['number_of_items'] ?? 20;
|
||||
@@ -61,7 +51,7 @@ class PersonListWidget implements WidgetInterface
|
||||
$qb->setParameter('centers', $centers);
|
||||
|
||||
// add the "only active" query
|
||||
if (array_key_exists('only_active', $config) && true === $config['only_active']) {
|
||||
if (\array_key_exists('only_active', $config) && true === $config['only_active']) {
|
||||
$qb->join('person.accompanyingPeriods', 'ap');
|
||||
$or = new Expr\Orx();
|
||||
// add the case where closingDate IS NULL
|
||||
@@ -74,19 +64,14 @@ class PersonListWidget implements WidgetInterface
|
||||
(new Expr())->between(':now', 'ap.openingDate', 'ap.closingDate')
|
||||
);
|
||||
$and->add($or);
|
||||
$qb->setParameter('now', new DateTime(), Types::DATE_MUTABLE);
|
||||
$qb->setParameter('now', new \DateTime(), Types::DATE_MUTABLE);
|
||||
}
|
||||
|
||||
if (array_key_exists('filtering_class', $config) && null !== $config['filtering_class']) {
|
||||
if (\array_key_exists('filtering_class', $config) && null !== $config['filtering_class']) {
|
||||
$filteringClass = new $config['filtering_class']();
|
||||
|
||||
if (!$filteringClass instanceof PersonListWidget\PersonFilteringInterface) {
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
'the class %s does not '
|
||||
. 'implements %s',
|
||||
$config['filtering_class'],
|
||||
PersonListWidget\PersonFilteringInterface::class
|
||||
));
|
||||
throw new \UnexpectedValueException(sprintf('the class %s does not implements %s', $config['filtering_class'], PersonListWidget\PersonFilteringInterface::class));
|
||||
}
|
||||
$ids = $filteringClass->getPersonIds(
|
||||
$this->entityManager,
|
||||
@@ -113,7 +98,7 @@ class PersonListWidget implements WidgetInterface
|
||||
$cfields = [];
|
||||
|
||||
if (isset($config['custom_fields'])) {
|
||||
if (count($config['custom_fields']) > 0) {
|
||||
if (\count($config['custom_fields']) > 0) {
|
||||
$cfs = $this->entityManager
|
||||
->getRepository(\Chill\CustomFieldsBundle\Entity\CustomField::class)
|
||||
->findBy(['slug' => $config['custom_fields']]);
|
||||
@@ -138,15 +123,13 @@ class PersonListWidget implements WidgetInterface
|
||||
$token = $this->tokenStorage->getToken();
|
||||
|
||||
if (null === $token) {
|
||||
throw new RuntimeException('the token should not be null');
|
||||
throw new \RuntimeException('the token should not be null');
|
||||
}
|
||||
|
||||
$user = $token->getUser();
|
||||
|
||||
if (null === $user) {
|
||||
throw new RuntimeException(
|
||||
'The user should implement UserInterface. Are you logged in ?'
|
||||
);
|
||||
throw new \RuntimeException('The user should implement UserInterface. Are you logged in ?');
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
@@ -34,7 +34,7 @@ class PersonListWidgetFactory extends AbstractWidgetFactory
|
||||
$node->arrayNode('custom_fields')
|
||||
->prototype('scalar')->end()
|
||||
->info('Add some custom field to the view. Add the slug of some custom field'
|
||||
. ' if you want to override the view and show their value in the list')
|
||||
.' if you want to override the view and show their value in the list')
|
||||
->example(['custom-field-slug-1', 'custom-field-slug-2'])
|
||||
->requiresAtLeastOneElement()
|
||||
->end();
|
||||
|
Reference in New Issue
Block a user