From 1e812564042cafc54e557824f035e4a98bbd05af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 8 Feb 2022 19:37:59 +0100 Subject: [PATCH] fix cs --- .../ChillCalendarBundle/Form/CalendarType.php | 1 - .../Controller/NotificationController.php | 8 +++-- .../Counter/WorkflowByUserCounter.php | 30 +++++++++---------- .../AccompanyingPeriodWork.php | 4 +-- .../Menu/AccompanyingCourseMenuBuilder.php | 2 -- .../AccompanyingPeriodWorkRepository.php | 11 ++++--- .../AccompanyingPeriodWorkVoter.php | 11 +++++-- .../ChillTaskBundle/Entity/SingleTask.php | 2 +- 8 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php index 8966ecca8..05dc362b4 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -97,7 +97,6 @@ class CalendarType extends AbstractType return $res; }, static function (?string $dateAsString): DateTimeImmutable { - return new DateTimeImmutable($dateAsString); } )); diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index 793810463..af9e1b2b1 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -235,7 +235,9 @@ class NotificationController extends AbstractController 'id' => $notification->getId(), '_fragment' => 'comment-' . $commentId, ]); - } elseif ($editedCommentForm->isSubmitted() && !$editedCommentForm->isValid()) { + } + + if ($editedCommentForm->isSubmitted() && !$editedCommentForm->isValid()) { $this->addFlash('error', $this->translator->trans('This form contains errors')); } } @@ -258,7 +260,9 @@ class NotificationController extends AbstractController return $this->redirectToRoute('chill_main_notification_show', [ 'id' => $notification->getId(), ]); - } elseif ($appendCommentForm->isSubmitted() && !$appendCommentForm->isValid()) { + } + + if ($appendCommentForm->isSubmitted() && !$appendCommentForm->isValid()) { $this->addFlash('error', $this->translator->trans('This form contains errors')); } } diff --git a/src/Bundle/ChillMainBundle/Workflow/Counter/WorkflowByUserCounter.php b/src/Bundle/ChillMainBundle/Workflow/Counter/WorkflowByUserCounter.php index 6a61e7de4..41ffd63c2 100644 --- a/src/Bundle/ChillMainBundle/Workflow/Counter/WorkflowByUserCounter.php +++ b/src/Bundle/ChillMainBundle/Workflow/Counter/WorkflowByUserCounter.php @@ -16,16 +16,16 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepRepository; use Chill\MainBundle\Templating\UI\NotificationCounterInterface; use Psr\Cache\CacheItemPoolInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Workflow\Event\Event; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; final class WorkflowByUserCounter implements NotificationCounterInterface, EventSubscriberInterface { - private EntityWorkflowStepRepository $workflowStepRepository; - private CacheItemPoolInterface $cacheItemPool; + private EntityWorkflowStepRepository $workflowStepRepository; + public function __construct(EntityWorkflowStepRepository $workflowStepRepository, CacheItemPoolInterface $cacheItemPool) { $this->workflowStepRepository = $workflowStepRepository; @@ -54,14 +54,21 @@ final class WorkflowByUserCounter implements NotificationCounterInterface, Event return $nb; } + public static function generateCacheKeyWorkflowByUser(User $user): string + { + return 'chill_main_workflow_by_u_' . $user->getId(); + } + public function getCountUnreadByUser(User $user): int { return $this->workflowStepRepository->countUnreadByUser($user); } - public static function generateCacheKeyWorkflowByUser(User $user): string + public static function getSubscribedEvents() { - return 'chill_main_workflow_by_u_'.$user->getId(); + return [ + 'workflow.leave' => 'resetWorkflowCache', + ]; } public function resetWorkflowCache(Event $event): void @@ -74,11 +81,12 @@ final class WorkflowByUserCounter implements NotificationCounterInterface, Event $entityWorkflow = $event->getSubject(); $step = $entityWorkflow->getCurrentStep(); - if ($step === null) { + if (null === $step) { return; } $keys = []; + foreach ($step->getDestUser() as $user) { $keys[] = self::generateCacheKeyWorkflowByUser($user); } @@ -86,15 +94,5 @@ final class WorkflowByUserCounter implements NotificationCounterInterface, Event if ([] !== $keys) { $this->cacheItemPool->deleteItems($keys); } - } - - public static function getSubscribedEvents() - { - return [ - 'workflow.leave' => 'resetWorkflowCache', - ]; - } - - } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index dff4ee38f..b7e8d1c5d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -44,8 +44,8 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues { /** * @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class) - * @Serializer\Groups({"read","read:accompanyingPeriodWork:light"}) - * @Serializer\Context(normalizationContext={"groups"={"read"}}, groups={"read:accompanyingPeriodWork:light"}) + * @Serializer\Groups({"read", "read:accompanyingPeriodWork:light"}) + * @Serializer\Context(normalizationContext={"groups": {"read"}}, groups={"read:accompanyingPeriodWork:light"}) */ private ?AccompanyingPeriod $accompanyingPeriod = null; diff --git a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php index b65e3a515..827dfb0a6 100644 --- a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php @@ -75,7 +75,6 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface ], ]) ->setExtras(['order' => 30]); - $menu->addChild($this->translator->trans('Accompanying Course Comment'), [ 'route' => 'chill_person_accompanying_period_comment_list', 'routeParameters' => [ @@ -93,7 +92,6 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface ->setExtras(['order' => 40]); } - $workflow = $this->registry->get($period, 'accompanying_period_lifecycle'); if (null !== $period->getClosingDate()) { diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index 7514517d5..9e67da458 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -25,10 +25,10 @@ use Doctrine\Persistence\ObjectRepository; final class AccompanyingPeriodWorkRepository implements ObjectRepository { - private EntityRepository $repository; - private EntityManagerInterface $em; + private EntityRepository $repository; + public function __construct(EntityManagerInterface $entityManager) { $this->em = $entityManager; @@ -84,7 +84,7 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository } /** - * Return a list of accompanying period with a defined order: + * Return a list of accompanying period with a defined order:. * * * first, opened works * * then, closed works @@ -96,7 +96,7 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository $rsm = new ResultSetMappingBuilder($this->em); $rsm->addRootEntityFromClassMetadata(AccompanyingPeriodWork::class, 'w'); - $sql = "SELECT ${rsm} FROM chill_person_accompanying_period_work w + $sql = "SELECT {$rsm} FROM chill_person_accompanying_period_work w WHERE accompanyingPeriod_id = :periodId ORDER BY CASE WHEN enddate IS NULL THEN '-infinity'::timestamp ELSE 'infinity'::timestamp END ASC, @@ -108,8 +108,7 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository $nq = $this->em->createNativeQuery($sql, $rsm) ->setParameter('periodId', $period->getId(), Types::INTEGER) ->setParameter('limit', $limit, Types::INTEGER) - ->setParameter('offset', $offset, Types::INTEGER) - ; + ->setParameter('offset', $offset, Types::INTEGER); return $nq->getResult(); } diff --git a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkVoter.php b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkVoter.php index 81b52f623..039baafaa 100644 --- a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkVoter.php +++ b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkVoter.php @@ -17,12 +17,15 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; use Symfony\Component\Security\Core\Security; use UnexpectedValueException; +use function get_class; use function in_array; class AccompanyingPeriodWorkVoter extends Voter { public const CREATE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_CREATE'; + public const SEE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_SEE'; + public const UPDATE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE'; private Security $security; @@ -40,7 +43,7 @@ class AccompanyingPeriodWorkVoter extends Voter && in_array($attribute, $this->getRoles(), true) ) || ( $subject instanceof AccompanyingPeriod - && in_array($attribute, [self::SEE, self::CREATE]) + && in_array($attribute, [self::SEE, self::CREATE], true) ); } @@ -64,8 +67,10 @@ class AccompanyingPeriodWorkVoter extends Voter return $this->security->isGranted(AccompanyingPeriodVoter::SEE_DETAILS, $subject); default: - throw new UnexpectedValueException(sprintf("attribute {$attribute} is not supported on instance %s", - AccompanyingPeriod::class)); + throw new UnexpectedValueException(sprintf( + "attribute {$attribute} is not supported on instance %s", + AccompanyingPeriod::class + )); } } diff --git a/src/Bundle/ChillTaskBundle/Entity/SingleTask.php b/src/Bundle/ChillTaskBundle/Entity/SingleTask.php index 67be85edc..2d9e3abcb 100644 --- a/src/Bundle/ChillTaskBundle/Entity/SingleTask.php +++ b/src/Bundle/ChillTaskBundle/Entity/SingleTask.php @@ -17,8 +17,8 @@ use DateTimeImmutable; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Serializer\Annotation as Serializer; +use Symfony\Component\Validator\Constraints as Assert; /** * SingleTask.