mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-06 06:44:59 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -25,9 +25,7 @@ use Chill\MainBundle\Redis\ChillRedis;
|
||||
use Chill\MainBundle\Repository\SavedExportRepositoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\SavedExportVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use LogicException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RedisException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
@@ -39,12 +37,8 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function count;
|
||||
use function serialize;
|
||||
use function unserialize;
|
||||
|
||||
/**
|
||||
* Class ExportController
|
||||
@@ -109,6 +103,7 @@ class ExportController extends AbstractController
|
||||
* @param string $alias
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/exports/generate/{alias}", name="chill_main_export_generate", methods={"GET"})
|
||||
*/
|
||||
public function generateAction(Request $request, $alias)
|
||||
@@ -131,7 +126,7 @@ class ExportController extends AbstractController
|
||||
/**
|
||||
* @Route("/{_locale}/exports/generate-from-saved/{id}", name="chill_main_export_generate_from_saved")
|
||||
*
|
||||
* @throws RedisException
|
||||
* @throws \RedisException
|
||||
*/
|
||||
public function generateFromSavedExport(SavedExport $savedExport): RedirectResponse
|
||||
{
|
||||
@@ -139,7 +134,7 @@ class ExportController extends AbstractController
|
||||
|
||||
$key = md5(uniqid((string) random_int(0, mt_getrandmax()), false));
|
||||
|
||||
$this->redis->setEx($key, 3600, serialize($savedExport->getOptions()));
|
||||
$this->redis->setEx($key, 3600, \serialize($savedExport->getOptions()));
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'chill_main_export_download',
|
||||
@@ -153,6 +148,7 @@ class ExportController extends AbstractController
|
||||
|
||||
/**
|
||||
* Render the list of available exports.
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/exports/", name="chill_main_export_index")
|
||||
*/
|
||||
public function indexAction(): Response
|
||||
@@ -186,7 +182,7 @@ class ExportController extends AbstractController
|
||||
$exportManager = $this->exportManager;
|
||||
$export = $exportManager->getExport($alias);
|
||||
|
||||
if ($exportManager->isGrantedForElement($export) === false) {
|
||||
if (false === $exportManager->isGrantedForElement($export)) {
|
||||
throw $this->createAccessDeniedException('The user does not have access to this export');
|
||||
}
|
||||
|
||||
@@ -279,7 +275,7 @@ class ExportController extends AbstractController
|
||||
$options = match ($step) {
|
||||
'export', 'generate_export' => [
|
||||
'export_alias' => $alias,
|
||||
'picked_centers' => $exportManager->getPickedCenters($data['centers'])
|
||||
'picked_centers' => $exportManager->getPickedCenters($data['centers']),
|
||||
],
|
||||
'formatter', 'generate_formatter' => [
|
||||
'export_alias' => $alias,
|
||||
@@ -332,7 +328,7 @@ class ExportController extends AbstractController
|
||||
* When the method is POST, the form is stored if valid, and a redirection
|
||||
* is done to next step.
|
||||
*/
|
||||
private function exportFormStep(Request $request, DirectExportInterface|ExportInterface $export, string $alias, ?SavedExport $savedExport = null): Response
|
||||
private function exportFormStep(Request $request, DirectExportInterface|ExportInterface $export, string $alias, SavedExport $savedExport = null): Response
|
||||
{
|
||||
$exportManager = $this->exportManager;
|
||||
|
||||
@@ -350,7 +346,7 @@ class ExportController extends AbstractController
|
||||
|
||||
$form = $this->createCreateFormExport($alias, 'export', $data, $savedExport);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
@@ -365,11 +361,11 @@ class ExportController extends AbstractController
|
||||
);
|
||||
$this->session->set('export_step', $data);
|
||||
|
||||
//redirect to next step
|
||||
// redirect to next step
|
||||
return $this->redirectToRoute('chill_main_export_new', [
|
||||
'step' => $this->getNextStep('export', $export),
|
||||
'alias' => $alias,
|
||||
'from_saved' => $request->get('from_saved', '')
|
||||
'from_saved' => $request->get('from_saved', ''),
|
||||
]);
|
||||
}
|
||||
$this->logger->debug('form export is invalid', [
|
||||
@@ -390,7 +386,7 @@ class ExportController extends AbstractController
|
||||
* If the form is posted and valid, store the data in session and
|
||||
* redirect to the next step.
|
||||
*/
|
||||
private function formatterFormStep(Request $request, DirectExportInterface|ExportInterface $export, string $alias, ?SavedExport $savedExport = null): Response
|
||||
private function formatterFormStep(Request $request, DirectExportInterface|ExportInterface $export, string $alias, SavedExport $savedExport = null): Response
|
||||
{
|
||||
// check we have data from the previous step (export step)
|
||||
$data = $this->session->get('export_step', null);
|
||||
@@ -404,7 +400,7 @@ class ExportController extends AbstractController
|
||||
|
||||
$form = $this->createCreateFormExport($alias, 'formatter', $data, $savedExport);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
@@ -415,7 +411,7 @@ class ExportController extends AbstractController
|
||||
$request->request->all()
|
||||
);
|
||||
|
||||
//redirect to next step
|
||||
// redirect to next step
|
||||
return $this->redirectToRoute('chill_main_export_new', [
|
||||
'alias' => $alias,
|
||||
'step' => $this->getNextStep('formatter', $export),
|
||||
@@ -440,12 +436,11 @@ class ExportController extends AbstractController
|
||||
*
|
||||
* The data from previous steps is removed from session.
|
||||
*
|
||||
* @param \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export
|
||||
* @param string $alias
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
private function forwardToGenerate(Request $request, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export, $alias, ?SavedExport $savedExport)
|
||||
private function forwardToGenerate(Request $request, DirectExportInterface|ExportInterface $export, $alias, ?SavedExport $savedExport)
|
||||
{
|
||||
$dataCenters = $this->session->get('centers_step_raw', null);
|
||||
$dataFormatter = $this->session->get('formatter_step_raw', null);
|
||||
@@ -468,7 +463,7 @@ class ExportController extends AbstractController
|
||||
unset($parameters['_token']);
|
||||
$key = md5(uniqid((string) random_int(0, mt_getrandmax()), false));
|
||||
|
||||
$this->redis->setEx($key, 3600, serialize($parameters));
|
||||
$this->redis->setEx($key, 3600, \serialize($parameters));
|
||||
|
||||
// remove data from session
|
||||
$this->session->remove('export_step_raw');
|
||||
@@ -497,7 +492,7 @@ class ExportController extends AbstractController
|
||||
$formExport->submit($rawData['export']);
|
||||
$dataExport = $formExport->getData();
|
||||
|
||||
if (count($rawData['formatter']) > 0) {
|
||||
if (\count($rawData['formatter']) > 0) {
|
||||
$formFormatter = $this->createCreateFormExport(
|
||||
$alias,
|
||||
'generate_formatter',
|
||||
@@ -513,16 +508,17 @@ class ExportController extends AbstractController
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
private function selectCentersStep(Request $request, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export, $alias, ?SavedExport $savedExport = null)
|
||||
private function selectCentersStep(Request $request, DirectExportInterface|ExportInterface $export, $alias, SavedExport $savedExport = null)
|
||||
{
|
||||
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */
|
||||
$exportManager = $this->exportManager;
|
||||
|
||||
$form = $this->createCreateFormExport($alias, 'centers', [], $savedExport);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
@@ -533,14 +529,13 @@ class ExportController extends AbstractController
|
||||
|
||||
// check ACL
|
||||
if (
|
||||
$exportManager->isGrantedForElement(
|
||||
false === $exportManager->isGrantedForElement(
|
||||
$export,
|
||||
null,
|
||||
$exportManager->getPickedCenters($data['centers'])
|
||||
) === false
|
||||
)
|
||||
) {
|
||||
throw $this->createAccessDeniedException('you do not have '
|
||||
. 'access to this export for those centers');
|
||||
throw $this->createAccessDeniedException('you do not have access to this export for those centers');
|
||||
}
|
||||
|
||||
$this->session->set(
|
||||
@@ -589,20 +584,19 @@ class ExportController extends AbstractController
|
||||
*
|
||||
* This method provides a centralized way of handling next/previous step.
|
||||
*
|
||||
* @param string $step the current step
|
||||
* @param \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export
|
||||
* @param bool $reverse set to true to get the previous step
|
||||
*
|
||||
* @throws LogicException if there is no step before or after the given step
|
||||
* @param string $step the current step
|
||||
* @param bool $reverse set to true to get the previous step
|
||||
*
|
||||
* @return string the next/current step
|
||||
*
|
||||
* @throws \LogicException if there is no step before or after the given step
|
||||
*/
|
||||
private function getNextStep($step, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export, $reverse = false)
|
||||
private function getNextStep($step, DirectExportInterface|ExportInterface $export, $reverse = false)
|
||||
{
|
||||
switch ($step) {
|
||||
case 'centers':
|
||||
if (false !== $reverse) {
|
||||
throw new LogicException("there is no step before 'export'");
|
||||
throw new \LogicException("there is no step before 'export'");
|
||||
}
|
||||
|
||||
return 'export';
|
||||
@@ -622,13 +616,13 @@ class ExportController extends AbstractController
|
||||
|
||||
case 'generate':
|
||||
if (false === $reverse) {
|
||||
throw new LogicException("there is no step after 'generate'");
|
||||
throw new \LogicException("there is no step after 'generate'");
|
||||
}
|
||||
|
||||
return 'formatter';
|
||||
|
||||
default:
|
||||
throw new LogicException("the step {$step} is not defined.");
|
||||
throw new \LogicException("the step {$step} is not defined.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,7 +632,7 @@ class ExportController extends AbstractController
|
||||
throw $this->createNotFoundException('key does not exists');
|
||||
}
|
||||
|
||||
if ($this->redis->exists($key) !== 1) {
|
||||
if (1 !== $this->redis->exists($key)) {
|
||||
$this->addFlash('error', $this->translator->trans('This report is not available any more'));
|
||||
|
||||
throw $this->createNotFoundException('key does not exists');
|
||||
@@ -647,10 +641,10 @@ class ExportController extends AbstractController
|
||||
$serialized = $this->redis->get($key);
|
||||
|
||||
if (false === $serialized) {
|
||||
throw new LogicException('the key could not be reached from redis');
|
||||
throw new \LogicException('the key could not be reached from redis');
|
||||
}
|
||||
|
||||
$rawData = unserialize($serialized);
|
||||
$rawData = \unserialize($serialized);
|
||||
|
||||
$this->logger->notice('[export] choices for an export unserialized', [
|
||||
'key' => $key,
|
||||
@@ -668,7 +662,7 @@ class ExportController extends AbstractController
|
||||
};
|
||||
|
||||
if (null !== $savedExport && !$this->security->isGranted(SavedExportVoter::EDIT, $savedExport)) {
|
||||
throw new AccessDeniedHttpException("saved export edition not allowed");
|
||||
throw new AccessDeniedHttpException('saved export edition not allowed');
|
||||
}
|
||||
|
||||
return $savedExport;
|
||||
|
Reference in New Issue
Block a user