fix: SA: Fix "might not be defined" rule.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 11:41:12 +01:00
parent a7b96f1756
commit f8aeb08594
14 changed files with 365 additions and 620 deletions

View File

@@ -23,6 +23,7 @@ use ArrayIterator;
use Chill\EventBundle\Entity\Event;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Chill\EventBundle\Entity\Participation;
@@ -183,7 +184,7 @@ class ParticipationController extends AbstractController
$participations = $this->handleRequest($request, new Participation(), true);
$ignoredParticipations = $newParticipations = [];
foreach ($participations as $i => $participation) {
foreach ($participations as $participation) {
// check for authorization
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
$participation, 'The user is not allowed to create this participation');
@@ -218,7 +219,9 @@ class ParticipationController extends AbstractController
return $this->redirectToRoute('chill_event__event_show', array(
'event_id' => $request->query->getInt('event_id', 0)
));
} elseif (count($newParticipations) > 1) {
}
if (count($newParticipations) > 1) {
// if we have multiple participations, show a form with multiple participations
$form = $this->createCreateFormMultiple($newParticipations);
@@ -372,9 +375,6 @@ class ParticipationController extends AbstractController
* If the request is multiple, the $participation object is cloned.
* Limitations: the $participation should not be persisted.
*
* @param Request $request
* @param Participation $participation
* @param boolean $multiple (default 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
@@ -382,7 +382,7 @@ class ParticipationController extends AbstractController
protected function handleRequest(
Request $request,
Participation $participation,
$multiple = false)
bool $multiple = false)
{
$em = $this->getDoctrine()->getManager();
if ($em->contains($participation)) {
@@ -441,11 +441,9 @@ class ParticipationController extends AbstractController
}
/**
* @param Participation $participation
* @param null $return_path
* @return \Symfony\Component\Form\FormInterface
*/
public function createCreateForm(Participation $participation, $return_path = null)
public function createCreateForm(Participation $participation, $return_path = null): FormInterface
{
$form = $this->createForm(ParticipationType::class, $participation, array(
@@ -464,11 +462,7 @@ class ParticipationController extends AbstractController
return $form;
}
/**
* @param array $participations
* @return \Symfony\Component\Form\FormInterface
*/
public function createCreateFormMultiple(array $participations)
public function createCreateFormMultiple(array $participations): FormInterface
{
$form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class,
array('participations' => $participations), array(
@@ -495,18 +489,16 @@ class ParticipationController extends AbstractController
}
/**
* show an edit form for the participation with the given id.
* Show an edit form for the participation with the given id.
*
* @param int $participation_id
* @return \Symfony\Component\HttpFoundation\Response
* @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
*/
public function editAction($participation_id)
public function editAction(int $participation_id): Response
{
/* @var $participation Participation */
$participation = $this->getDoctrine()->getManager()
->getRepository('ChillEventBundle:Participation')
->getRepository(Participation::class)
->find($participation_id);
if ($participation === NULL) {
@@ -518,22 +510,17 @@ class ParticipationController extends AbstractController
$form = $this->createEditForm($participation);
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
return $this->render('ChillEventBundle:Participation:edit.html.twig', [
'form' => $form->createView(),
'participation' => $participation
));
'participation' => $participation,
]);
}
/**
* @param $participation_id
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function updateAction($participation_id, Request $request)
public function updateAction(int $participation_id, Request $request): Response
{
/* @var $participation Participation */
$participation = $this->getDoctrine()->getManager()
->getRepository('ChillEventBundle:Participation')
->getRepository(Participation::class)
->find($participation_id);
if ($participation === NULL) {
@@ -556,35 +543,40 @@ class ParticipationController extends AbstractController
'The participation was updated'
));
return $this->redirectToRoute('chill_event__event_show', array(
'event_id' => $participation->getEvent()->getId()
));
return $this->redirectToRoute('chill_event__event_show', [
'event_id' => $participation->getEvent()->getId(),
]);
}
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
return $this->render('ChillEventBundle:Participation:edit.html.twig', [
'form' => $form->createView(),
'participation' => $participation
));
'participation' => $participation,
]);
}
/**
*
* @param Participation $participation
* @return \Symfony\Component\Form\FormInterface
*/
public function createEditForm(Participation $participation)
public function createEditForm(Participation $participation): FormInterface
{
$form = $this->createForm(ParticipationType::class, $participation, array(
'event_type' => $participation->getEvent()->getType(),
'action' => $this->generateUrl('chill_event_participation_update', array(
'participation_id' => $participation->getId()
))
));
$form = $this->createForm(
ParticipationType::class,
$participation,
[
'event_type' => $participation->getEvent()->getType(),
'action' => $this->generateUrl(
'chill_event_participation_update',
[
'participation_id' => $participation->getId(),
]
),
]
);
$form->add('submit', SubmitType::class, array(
'label' => 'Edit'
));
$form->add(
'submit',
SubmitType::class, [
'label' => 'Edit',
]
);
return $form;
}