cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,45 +1,48 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\TaskBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Chill\TaskBundle\Entity\AbstractTask;
use Chill\TaskBundle\Event\UI\UIEvent;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Chill\TaskBundle\Event\UI\UIEvent;
use Chill\TaskBundle\Entity\AbstractTask;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\Transition;
use function array_filter;
use function array_values;
/**
* Class TaskController
*
* @package Chill\TaskBundle\Controller
* Class TaskController.
*/
class TaskController extends AbstractController
{
/**
* Apply a transition to a task
* Apply a transition to a task.
*
* @Route(
* "/{_locale}/task/transition/{kind}/{taskId}/{transition}",
* name="chill_task_task_transition"
* "/{_locale}/task/transition/{kind}/{taskId}/{transition}",
* name="chill_task_task_transition"
* )
*
* @param string $kind
* @param int $taskId
* @param string $transition
* @param SingleTaskRepository $singleTaskRepository
* @param Registry $registry
* @param EntityManagerInterface $em
* @param Request $request
* @param TranslatorInterface $translator
*
* @return Response
*/
public function applyTransitionAction(
@@ -56,91 +59,90 @@ class TaskController extends AbstractController
switch ($kind) {
case 'single-task':
$task = $singleTaskRepository
->find($taskId)
;
->find($taskId);
$defaultReturnPath = $this->generateUrl(
'chill_task_single_task_show',
[
[
'id' => $task->getId(),
'list_params' => $request->query->get('list_params', [])
]);
'list_params' => $request->query->get('list_params', []),
]
);
$task->getCourse() === null ? $defaultTemplate = '@ChillTask/SingleTask/Person/transition.html.twig' : $defaultTemplate = '@ChillTask/SingleTask/AccompanyingCourse/transition.html.twig';
break;
default:
return new Response("The type '$kind' is not implemented",
Response::HTTP_BAD_REQUEST);
return new Response(
"The type '{$kind}' is not implemented",
Response::HTTP_BAD_REQUEST
);
}
if (NULL === $task) {
throw $this->createNotFoundException("task with id '$taskId' and type "
. "'$type' does not exists");
if (null === $task) {
throw $this->createNotFoundException("task with id '{$taskId}' and type "
. "'{$type}' does not exists");
}
$workflow = $registry->get($task);
if (!$workflow->can($task, $transition)) {
throw $this->createAccessDeniedException('You are not allowed to apply this transition');
}
$transitionInstance = \array_values( // array_values needed to reset keys (array_filter preserves keys)
\array_filter(
$workflow->getEnabledTransitions($task),
function(Transition $t) use ($transition) {
$transitionInstance = array_values( // array_values needed to reset keys (array_filter preserves keys)
array_filter(
$workflow->getEnabledTransitions($task),
function (Transition $t) use ($transition) {
return $t->getName() === $transition;
}
))[0];
$form = $this->createTransitionForm($task);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
))[0];
$form = $this->createTransitionForm($task);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($workflow->can($task, $transition)) {
$workflow->apply($task, $transition);
$em->flush();
$this->addFlash('success', $translator->trans('The transition is successfully applied'));
} else {
$this->addFlash('error', $translator->trans('The transition could not be applied'));
}
return $this->redirect($defaultReturnPath);
} else {
$event = (new UIEvent($kind, $task))
->setForm($form)
->setTransition($transitionInstance)
;
$eventDispatcher->dispatch(UIEvent::SHOW_TRANSITION_PAGE, $event);
if ($event->hasResponse()) {
return $event->getResponse();
} else {
// we simply check that the user can see the task. Other ACL checks
// should be performed using `guard` events.
$this->denyAccessUnlessGranted(TaskVoter::SHOW, $task);
return $this->render($defaultTemplate, [
'task' => $task,
'form' => $form->createView(),
'transition' => $transitionInstance
]);
}
}
$event = (new UIEvent($kind, $task))
->setForm($form)
->setTransition($transitionInstance);
$eventDispatcher->dispatch(UIEvent::SHOW_TRANSITION_PAGE, $event);
if ($event->hasResponse()) {
return $event->getResponse();
}
// we simply check that the user can see the task. Other ACL checks
// should be performed using `guard` events.
$this->denyAccessUnlessGranted(TaskVoter::SHOW, $task);
return $this->render($defaultTemplate, [
'task' => $task,
'form' => $form->createView(),
'transition' => $transitionInstance,
]);
}
/**
*
* @param \Chill\TaskBundle\Controller\AbstractTask $task
*
* @return \Symfony\Component\Form\FormInterface
*/
protected function createTransitionForm(AbstractTask $task)
{
$builder = $this->createFormBuilder($task);
$builder->add('submit', SubmitType::class);
return $builder->getForm();
}
}