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

@@ -11,16 +11,12 @@ declare(strict_types=1);
namespace Chill\EventBundle\Controller;
use ArrayIterator;
use Chill\EventBundle\Entity\Event;
use Chill\EventBundle\Entity\Participation;
use Chill\EventBundle\Form\ParticipationType;
use Chill\EventBundle\Security\Authorization\ParticipationVoter;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection;
use LogicException;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@@ -28,8 +24,6 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use function count;
/**
* Class ParticipationController.
*/
@@ -41,15 +35,14 @@ class ParticipationController extends AbstractController
public function __construct(private readonly LoggerInterface $logger) {}
/**
* @return Response|\Symfony\Component\HttpFoundation\RedirectResponse
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/create", name="chill_event_participation_create")
*/
public function createAction(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
public function createAction(Request $request): Response|\Symfony\Component\HttpFoundation\RedirectResponse
{
// test the request is correct
try {
$this->testRequest($request);
} catch (RuntimeException $ex) {
} catch (\RuntimeException $ex) {
$this->logger->warning($ex->getMessage());
return (new Response())
@@ -73,7 +66,7 @@ class ParticipationController extends AbstractController
return (new Response())
->setStatusCode(Response::HTTP_BAD_REQUEST)
->setContent("You must provide either 'person_id' or "
. "'persons_ids' argument in query");
."'persons_ids' argument in query");
}
/**
@@ -159,10 +152,7 @@ class ParticipationController extends AbstractController
return $form;
}
/**
* @return Response|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function createMultiple(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
public function createMultiple(Request $request): Response|\Symfony\Component\HttpFoundation\RedirectResponse
{
$participations = $this->handleRequest($request, new Participation(), true);
@@ -202,10 +192,7 @@ class ParticipationController extends AbstractController
]);
}
/**
* @return Response|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function createSingle(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
public function createSingle(Request $request): Response|\Symfony\Component\HttpFoundation\RedirectResponse
{
$participation = $this->handleRequest($request, new Participation(), false);
@@ -246,10 +233,9 @@ class ParticipationController extends AbstractController
/**
* @param int $participation_id
*
* @return Response|\Symfony\Component\HttpFoundation\RedirectResponse
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/{participation_id}/delete", name="chill_event_participation_delete", requirements={"participation_id"="\d+"}, methods={"GET", "DELETE"})
*/
public function deleteAction($participation_id, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
public function deleteAction($participation_id, Request $request): Response|\Symfony\Component\HttpFoundation\RedirectResponse
{
$em = $this->getDoctrine()->getManager();
$participation = $em->getRepository(\Chill\EventBundle\Entity\Participation::class)->findOneBy([
@@ -265,7 +251,7 @@ class ParticipationController extends AbstractController
$form = $this->createDeleteForm($participation_id);
if ($request->getMethod() === Request::METHOD_DELETE) {
if (Request::METHOD_DELETE === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
@@ -293,8 +279,9 @@ class ParticipationController extends AbstractController
/**
* Show an edit form for the participation with the given id.
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the participation is not found
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the participation is not found
* @throws \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException if the user is not allowed to edit the participation
*
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/{participation_id}/edit", name="chill_event_participation_edit")
*/
public function editAction(int $participation_id): Response
@@ -327,10 +314,9 @@ class ParticipationController extends AbstractController
*
* @param int $event_id
*
* @return Response|\Symfony\Component\HttpFoundation\RedirectResponse
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/{event_id}/edit_multiple", name="chill_event_participation_edit_multiple")
*/
public function editMultipleAction($event_id): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
public function editMultipleAction($event_id): Response|\Symfony\Component\HttpFoundation\RedirectResponse
{
$event = $this->getDoctrine()->getRepository(\Chill\EventBundle\Entity\Event::class)
->find($event_id);
@@ -341,13 +327,13 @@ class ParticipationController extends AbstractController
// check for ACL, on Event level and on Participation Level
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, 'You are not allowed '
. 'to see this event');
.'to see this event');
foreach ($event->getParticipations() as $participation) {
$this->denyAccessUnlessGranted(
ParticipationVoter::UPDATE,
$participation,
'You are not allowed to update participation with id ' . $participation->getId()
'You are not allowed to update participation with id '.$participation->getId()
);
}
@@ -385,15 +371,14 @@ class ParticipationController extends AbstractController
* and decide if it should process a single or multiple participation. Depending
* on this, the appropriate layout and form.
*
* @return Response|\Symfony\Component\HttpFoundation\RedirectResponse
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/new", name="chill_event_participation_new")
*/
public function newAction(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
public function newAction(Request $request): Response|\Symfony\Component\HttpFoundation\RedirectResponse
{
// test the request is correct
try {
$this->testRequest($request);
} catch (RuntimeException $ex) {
} catch (\RuntimeException $ex) {
$this->logger->warning($ex->getMessage());
return (new Response())
@@ -417,7 +402,7 @@ class ParticipationController extends AbstractController
return (new Response())
->setStatusCode(Response::HTTP_BAD_REQUEST)
->setContent("You must provide either 'person_id' or "
. "'persons_ids' argument in query");
."'persons_ids' argument in query");
}
/**
@@ -478,13 +463,13 @@ class ParticipationController extends AbstractController
}
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, 'You are not allowed '
. 'to see this event');
.'to see this event');
foreach ($event->getParticipations() as $participation) {
$this->denyAccessUnlessGranted(
ParticipationVoter::UPDATE,
$participation,
'You are not allowed to update participation with id ' . $participation->getId()
'You are not allowed to update participation with id '.$participation->getId()
);
}
@@ -496,7 +481,7 @@ class ParticipationController extends AbstractController
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->get('translator')->trans('The participations '
. 'have been successfully updated.'));
.'have been successfully updated.'));
return $this->redirectToRoute(
'chill_event__event_show',
@@ -551,10 +536,10 @@ class ParticipationController extends AbstractController
* If the request is multiple, the $participation object is cloned.
* Limitations: the $participation should not be persisted.
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person
* @return Participation|Participation[] return one single participation if $multiple == false
*
* @return Participation|Participations[] return one single participation if $multiple == false
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person
*/
protected function handleRequest(
Request $request,
@@ -564,8 +549,7 @@ class ParticipationController extends AbstractController
$em = $this->getDoctrine()->getManager();
if ($em->contains($participation)) {
throw new LogicException('The participation object should not be managed by '
. 'the object manager using the method ' . __METHOD__);
throw new \LogicException('The participation object should not be managed by the object manager using the method '.__METHOD__);
}
$event_id = $request->query->getInt('event_id', 0); // sf4 check:
@@ -576,7 +560,7 @@ class ParticipationController extends AbstractController
->find($event_id);
if (null === $event) {
throw $this->createNotFoundException('The event with id ' . $event_id . ' is not found');
throw $this->createNotFoundException('The event with id '.$event_id.' is not found');
}
$this->denyAccessUnlessGranted(
@@ -598,14 +582,14 @@ class ParticipationController extends AbstractController
foreach ($persons_ids as $person_id) {
// clone if we have to reuse the $participation
$participation = count($persons_ids) > 1 ? clone $participation : $participation;
$participation = \count($persons_ids) > 1 ? clone $participation : $participation;
if (null !== $person_id) {
$person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
if (null === $person) {
throw $this->createNotFoundException('The person with id ' . $person_id . ' is not found');
throw $this->createNotFoundException('The person with id '.$person_id.' is not found');
}
$this->denyAccessUnlessGranted(
@@ -634,16 +618,14 @@ class ParticipationController extends AbstractController
*
* If all participations must be ignored, an error is shown and the method redirects
* to the event 'show' view with an appropriate flash message.
*
* @return Response|\Symfony\Component\HttpFoundation\RedirectResponse
*/
protected function newMultiple(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
protected function newMultiple(Request $request): Response|\Symfony\Component\HttpFoundation\RedirectResponse
{
$participations = $this->handleRequest($request, new Participation(), true);
$ignoredParticipations = $newParticipations = [];
foreach ($participations as $participation) {
/** @var Participation $participation */
/* @var Participation $participation */
// check for authorization
$this->denyAccessUnlessGranted(
ParticipationVoter::CREATE,
@@ -652,7 +634,6 @@ class ParticipationController extends AbstractController
);
// create a collection of person's id participating to the event
/** @var \Doctrine\Common\Collections\ArrayCollection $peopleParticipating */
$peopleParticipating ??= $participation->getEvent()->getParticipations()->map(
static fn (Participation $p) => $p->getPerson()->getId()
);
@@ -673,7 +654,7 @@ class ParticipationController extends AbstractController
// if we do not have nay participants, redirect to event view
$this->addFlash('error', $this->get('translator')->trans(
'None of the requested people may participate '
. 'the event: they are maybe already participating.'
.'the event: they are maybe already participating.'
));
return $this->redirectToRoute('chill_event__event_show', [
@@ -681,7 +662,7 @@ class ParticipationController extends AbstractController
]);
}
if (count($newParticipations) > 1) {
if (\count($newParticipations) > 1) {
// if we have multiple participations, show a form with multiple participations
$form = $this->createCreateFormMultiple($newParticipations);
@@ -742,7 +723,7 @@ class ParticipationController extends AbstractController
* - `person_id` and `persons_ids` are **not** both present ;
* - `persons_id` is correct (contains only numbers and a ','.
*
* @throws RuntimeException if an error is detected
* @throws \RuntimeException if an error is detected
*/
protected function testRequest(Request $request)
{
@@ -751,28 +732,24 @@ class ParticipationController extends AbstractController
if (true === $single && true === $multiple) {
// we are not allowed to have both person_id and persons_ids
throw new RuntimeException("You are not allow to provide both 'person_id' and "
. "'persons_ids' simulaneously");
throw new \RuntimeException("You are not allow to provide both 'person_id' and 'persons_ids' simulaneously");
}
if (true === $multiple) {
$persons_ids = $request->query->get('persons_ids');
if (!preg_match('/^([0-9]{1,},{0,1}){1,}[0-9]{0,}$/', (string) $persons_ids)) {
throw new RuntimeException('The persons_ids value should '
. "contains int separated by ','");
throw new \RuntimeException('The persons_ids value should '."contains int separated by ','");
}
}
// check for event_id - this could be removed later
if ($request->query->has('event_id') === false) {
throw new RuntimeException('You must provide an event_id');
if (false === $request->query->has('event_id')) {
throw new \RuntimeException('You must provide an event_id');
}
}
/**
* @param $participation_id
*
* @return \Symfony\Component\Form\FormInterface
*/
private function createDeleteForm($participation_id)