mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -18,7 +18,6 @@ use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use DateTime;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -27,9 +26,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
use function array_filter;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Class AccompanyingPeriodController.
|
||||
@@ -57,6 +54,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/accompanying-period/close", name="chill_person_accompanying_period_close")
|
||||
*/
|
||||
public function closeAction(int $person_id, Request $request): Response
|
||||
@@ -65,7 +63,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person');
|
||||
|
||||
if ($person->isOpen() === false) {
|
||||
if (false === $person->isOpen()) {
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('error', $this->get('translator')
|
||||
->trans(
|
||||
@@ -85,14 +83,14 @@ class AccompanyingPeriodController extends AbstractController
|
||||
'center' => $person->getCenter(),
|
||||
]);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$person->close($current);
|
||||
$errors = $this->_validatePerson($person);
|
||||
|
||||
if (count($errors) === 0) {
|
||||
if (0 === \count($errors)) {
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('success', $this->get('translator')
|
||||
->trans('An accompanying period has been closed.', [
|
||||
@@ -113,7 +111,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('info', $error->getMessage());
|
||||
}
|
||||
} else { //if form is not valid
|
||||
} else { // if form is not valid
|
||||
$this->get('session')->getFlashBag()
|
||||
->add(
|
||||
'error',
|
||||
@@ -148,11 +146,11 @@ class AccompanyingPeriodController extends AbstractController
|
||||
'You are not allowed to update this person'
|
||||
);
|
||||
|
||||
$accompanyingPeriod = new AccompanyingPeriod(new DateTime('now'));
|
||||
$accompanyingPeriod->setClosingDate(new DateTime('now'));
|
||||
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime('now'));
|
||||
$accompanyingPeriod->setClosingDate(new \DateTime('now'));
|
||||
|
||||
$accompanyingPeriod->addPerson($person);
|
||||
//or $person->addAccompanyingPeriod($accompanyingPeriod);
|
||||
// or $person->addAccompanyingPeriod($accompanyingPeriod);
|
||||
|
||||
$form = $this->createForm(
|
||||
AccompanyingPeriodType::class,
|
||||
@@ -163,14 +161,14 @@ class AccompanyingPeriodController extends AbstractController
|
||||
]
|
||||
);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
$errors = $this->_validatePerson($person);
|
||||
$flashBag = $this->get('session')->getFlashBag();
|
||||
|
||||
if (
|
||||
$form->isValid(['Default', 'closed'])
|
||||
&& count($errors) === 0
|
||||
&& 0 === \count($errors)
|
||||
) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($accompanyingPeriod);
|
||||
@@ -203,6 +201,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
|
||||
/**
|
||||
* @ParamConverter("person", options={"id": "person_id"})
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/accompanying-period", name="chill_person_accompanying_period_list")
|
||||
*/
|
||||
public function listAction(Person $person): Response
|
||||
@@ -216,12 +215,12 @@ class AccompanyingPeriodController extends AbstractController
|
||||
$this->eventDispatcher->dispatch($event, PrivacyEvent::PERSON_PRIVACY_EVENT);
|
||||
|
||||
$accompanyingPeriods = $this->accompanyingPeriodACLAwareRepository
|
||||
->findByPerson($person, AccompanyingPeriodVoter::SEE, ["openingDate" => "DESC", "id" => "DESC"]);
|
||||
->findByPerson($person, AccompanyingPeriodVoter::SEE, ['openingDate' => 'DESC', 'id' => 'DESC']);
|
||||
|
||||
//usort($accompanyingPeriodsRaw, static fn ($a, $b) => $b->getOpeningDate() <=> $a->getOpeningDate());
|
||||
// usort($accompanyingPeriodsRaw, static fn ($a, $b) => $b->getOpeningDate() <=> $a->getOpeningDate());
|
||||
|
||||
// filter visible or not visible
|
||||
//$accompanyingPeriods = array_filter($accompanyingPeriodsRaw, fn (AccompanyingPeriod $ap) => $this->isGranted(AccompanyingPeriodVoter::SEE, $ap));
|
||||
// $accompanyingPeriods = array_filter($accompanyingPeriodsRaw, fn (AccompanyingPeriod $ap) => $this->isGranted(AccompanyingPeriodVoter::SEE, $ap));
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingPeriod/list.html.twig', [
|
||||
'accompanying_periods' => $accompanyingPeriods,
|
||||
@@ -242,7 +241,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
'You are not allowed to update this person'
|
||||
);
|
||||
|
||||
//in case the person is already open
|
||||
// in case the person is already open
|
||||
if ($person->isOpen()) {
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('error', $this->get('translator')
|
||||
@@ -256,7 +255,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
$accompanyingPeriod = new AccompanyingPeriod(new DateTime());
|
||||
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
|
||||
|
||||
$form = $this->createForm(
|
||||
AccompanyingPeriodType::class,
|
||||
@@ -267,7 +266,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
]
|
||||
);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
@@ -275,7 +274,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
|
||||
$errors = $this->_validatePerson($person);
|
||||
|
||||
if (count($errors) <= 0) {
|
||||
if (\count($errors) <= 0) {
|
||||
$this->get('session')->getFlashBag()
|
||||
->add('success', $this->get('translator')
|
||||
->trans(
|
||||
@@ -323,9 +322,9 @@ class AccompanyingPeriodController extends AbstractController
|
||||
$person = $this->_getPerson($person_id);
|
||||
|
||||
/** @var AccompanyingPeriod $period */
|
||||
$period = array_filter(
|
||||
$period = \array_filter(
|
||||
$person->getAccompanyingPeriods(),
|
||||
static fn (AccompanyingPeriod $p) => $p->getId() === ($period_id)
|
||||
static fn (AccompanyingPeriod $p) => $p->getId() === $period_id
|
||||
)[0] ?? null;
|
||||
|
||||
if (null === $period) {
|
||||
@@ -364,6 +363,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/accompanying-period/{period_id}/update", name="chill_person_accompanying_period_update")
|
||||
*/
|
||||
public function updateAction(int $person_id, int $period_id, Request $request): Response
|
||||
@@ -374,7 +374,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
$accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($period_id);
|
||||
|
||||
if (null === $accompanyingPeriod) {
|
||||
throw $this->createNotFoundException('Period with id ' . $period_id . ' is not found');
|
||||
throw $this->createNotFoundException('Period with id '.$period_id.' is not found');
|
||||
}
|
||||
|
||||
/** @var Person $person */
|
||||
@@ -382,7 +382,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
|
||||
// CHECK
|
||||
if (!$accompanyingPeriod->containsPerson($person)) {
|
||||
throw new Exception('Accompanying period ' . $period_id . ' does not contain person ' . $person_id);
|
||||
throw new Exception('Accompanying period '.$period_id.' does not contain person '.$person_id);
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
@@ -400,14 +400,14 @@ class AccompanyingPeriodController extends AbstractController
|
||||
]
|
||||
);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
$errors = $this->_validatePerson($person);
|
||||
$flashBag = $this->get('session')->getFlashBag();
|
||||
|
||||
if (
|
||||
$form->isValid(['Default', 'closed'])
|
||||
&& count($errors) === 0
|
||||
&& 0 === \count($errors)
|
||||
) {
|
||||
$em->flush();
|
||||
|
||||
|
Reference in New Issue
Block a user