From eccc75aecf402ea830248b7a5a9d299750bab617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 23 Jan 2022 23:22:04 +0100 Subject: [PATCH] fix cs --- ...nyingPeriodWorkEvaluationApiController.php | 15 +++--- ...mpanyingPeriodWorkEvaluationRepository.php | 47 +++++++++++-------- .../AccompanyingPeriodWorkRepository.php | 44 ++++++++--------- .../Controller/SingleTaskController.php | 10 ++-- .../ChillTaskBundle/Entity/AbstractTask.php | 4 +- 5 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php index a1b857ac2..e82877637 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php @@ -18,8 +18,6 @@ use Chill\MainBundle\Serializer\Model\Collection; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; use Chill\PersonBundle\Entity\SocialWork\Evaluation; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationRepository; -use DateTimeImmutable; -use DateInterval; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -39,10 +37,10 @@ class AccompanyingPeriodWorkEvaluationApiController private PaginatorFactory $paginatorFactory; - private SerializerInterface $serializer; - private Security $security; + private SerializerInterface $serializer; + public function __construct( AccompanyingPeriodWorkEvaluationRepository $accompanyingPeriodWorkEvaluationRepository, DocGeneratorTemplateRepository $docGeneratorTemplateRepository, @@ -92,8 +90,6 @@ class AccompanyingPeriodWorkEvaluationApiController /** * @Route("/api/1.0/person/accompanying-period/work/evaluation/my-near-end") - * @param Request $request - * @return JsonResponse */ public function myWorksNearEndDate(Request $request): JsonResponse { @@ -101,8 +97,11 @@ class AccompanyingPeriodWorkEvaluationApiController ->countNearMaxDateByUser($this->security->getUser()); $paginator = $this->paginatorFactory->create($total); $works = $this->accompanyingPeriodWorkEvaluationRepository - ->findNearMaxDateByUser($this->security->getUser(), - $paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber()); + ->findNearMaxDateByUser( + $this->security->getUser(), + $paginator->getItemsPerPage(), + $paginator->getCurrentPageFirstItemNumber() + ); $collection = new Collection($works, $paginator); diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationRepository.php index bf273b502..ca1a01157 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationRepository.php @@ -1,5 +1,14 @@ repository = $entityManager->getRepository(AccompanyingPeriodWorkEvaluation::class); } + public function countNearMaxDateByUser(User $user): int + { + return $this->buildQueryNearMaxDateByUser($user) + ->select('count(e)')->getQuery()->getSingleScalarResult(); + } + public function find($id): ?AccompanyingPeriodWorkEvaluation { return $this->repository->find($id); @@ -34,10 +48,9 @@ class AccompanyingPeriodWorkEvaluationRepository implements ObjectRepository } /** - * @param array $criteria - * @param array|null $orderBy * @param int $limit * @param int $offset + * * @return array|AccompanyingPeriodWorkEvaluation[]|object[] */ public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array @@ -45,22 +58,6 @@ class AccompanyingPeriodWorkEvaluationRepository implements ObjectRepository return $this->repository->findBy($criteria, $orderBy, $limit, $offset); } - public function findOneBy(array $criteria): ?AccompanyingPeriodWorkEvaluation - { - return $this->repository->findOneBy($criteria); - } - - public function getClassName(): string - { - return AccompanyingPeriodWorkEvaluation::class; - } - - public function countNearMaxDateByUser(User $user): int - { - return $this->buildQueryNearMaxDateByUser($user) - ->select('count(e)')->getQuery()->getSingleScalarResult(); - } - public function findNearMaxDateByUser(User $user, int $limit = 20, int $offset = 0): array { return $this->buildQueryNearMaxDateByUser($user) @@ -71,6 +68,16 @@ class AccompanyingPeriodWorkEvaluationRepository implements ObjectRepository ->getResult(); } + public function findOneBy(array $criteria): ?AccompanyingPeriodWorkEvaluation + { + return $this->repository->findOneBy($criteria); + } + + public function getClassName(): string + { + return AccompanyingPeriodWorkEvaluation::class; + } + private function buildQueryNearMaxDateByUser(User $user): QueryBuilder { $qb = $this->repository->createQueryBuilder('e'); @@ -87,7 +94,7 @@ class AccompanyingPeriodWorkEvaluationRepository implements ObjectRepository ) ->setParameters([ 'user' => $user, - 'now' => new \DateTimeImmutable('now') + 'now' => new DateTimeImmutable('now'), ]); return $qb; diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index dfd556e2a..1b56b6cdf 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -29,28 +29,6 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository $this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class); } - private function buildQueryNearEndDateByUser(User $user, DateTimeImmutable $since, DateTimeImmutable $until): QueryBuilder - { - $qb = $this->repository->createQueryBuilder('w'); - - $qb - ->join('w.accompanyingPeriod', 'period') - ->where( - $qb->expr()->andX( - $qb->expr()->eq('period.user', ':user'), - $qb->expr()->gte('w.endDate', ':since'), - $qb->expr()->lte('w.startDate', ':until') - ) - ) - ->setParameters([ - 'user' => $user, - 'since' => $since, - 'until' => $until, - ]); - - return $qb; - } - public function countByAccompanyingPeriod(AccompanyingPeriod $period): int { return $this->repository->countByAccompanyingPeriod($period); @@ -152,4 +130,26 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository return $qb; } + + private function buildQueryNearEndDateByUser(User $user, DateTimeImmutable $since, DateTimeImmutable $until): QueryBuilder + { + $qb = $this->repository->createQueryBuilder('w'); + + $qb + ->join('w.accompanyingPeriod', 'period') + ->where( + $qb->expr()->andX( + $qb->expr()->eq('period.user', ':user'), + $qb->expr()->gte('w.endDate', ':since'), + $qb->expr()->lte('w.startDate', ':until') + ) + ) + ->setParameters([ + 'user' => $user, + 'since' => $since, + 'until' => $until, + ]); + + return $qb; + } } diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index fae54b6ae..bac4c1a2a 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -478,11 +478,15 @@ final class SingleTaskController extends AbstractController case 'json': $collection = new Collection($tasks, $paginator); - return $this->json($collection, JsonResponse::HTTP_OK, [], - ['groups' => ['read']]); + return $this->json( + $collection, + JsonResponse::HTTP_OK, + [], + ['groups' => ['read']] + ); default: - throw new BadRequestException("format not supported: $format"); + throw new BadRequestException("format not supported: {$format}"); } } diff --git a/src/Bundle/ChillTaskBundle/Entity/AbstractTask.php b/src/Bundle/ChillTaskBundle/Entity/AbstractTask.php index a4b154d2b..267bd8bcd 100644 --- a/src/Bundle/ChillTaskBundle/Entity/AbstractTask.php +++ b/src/Bundle/ChillTaskBundle/Entity/AbstractTask.php @@ -29,8 +29,8 @@ use function array_keys; * * @ORM\MappedSuperclass * @Serializer\DiscriminatorMap(typeProperty="type", mapping={ - * "single_task": SingleTask::class - * }) + * "single_task": SingleTask::class + * }) */ abstract class AbstractTask implements HasCenterInterface, HasScopeInterface {