Fix cs after php-cs-fixer upgrade, fix phpstan and rector errors

This commit is contained in:
2024-09-05 18:00:37 +02:00
parent e29e1db6ed
commit e8f09b507f
5 changed files with 39 additions and 26 deletions

View File

@@ -1,16 +1,26 @@
<?php
declare(strict_types=1);
/*
* 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\MainBundle\Controller;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepHold;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepHoldRepository;
use Chill\MainBundle\Security\ChillSecurity;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Workflow\Registry;
@@ -22,7 +32,7 @@ class WorkflowOnHoldController extends AbstractController
private readonly Security $security,
private readonly Registry $registry,
private readonly EntityWorkflowStepHoldRepository $entityWorkflowStepHoldRepository,
private readonly EntityWorkflowRepository $entityWorkflowRepository
private readonly EntityWorkflowRepository $entityWorkflowRepository,
) {}
#[Route(path: '/{_locale}/main/workflow/{id}/hold', name: 'chill_main_workflow_on_hold')]
@@ -33,10 +43,14 @@ class WorkflowOnHoldController extends AbstractController
$currentStep = $entityWorkflow->getCurrentStep();
$currentUser = $this->security->getUser();
if (!$currentUser instanceof User) {
throw new AccessDeniedHttpException('only user can put a workflow on hold');
}
$workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName());
$enabledTransitions = $workflow->getEnabledTransitions($entityWorkflow);
if (!count($enabledTransitions) > 0) {
if (0 === count($enabledTransitions)) {
throw $this->createAccessDeniedException('You are not allowed to apply any transitions to this workflow, therefore you cannot toggle the hold status.');
}
@@ -64,5 +78,4 @@ class WorkflowOnHoldController extends AbstractController
return $this->redirectToRoute('chill_main_workflow_show', ['id' => $entityWorkflow->getId()]);
}
}