mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
DX: apply rector rules up to php8.0
This commit is contained in:
@@ -62,17 +62,15 @@ class CRUDController extends AbstractController
|
||||
*
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function edit(Request $request, $id): Response
|
||||
public function edit(Request $request, mixed $id): Response
|
||||
{
|
||||
return $this->formEditAction('edit', $request, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context for the serialization.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function getContextForSerialization(string $action, Request $request, $entity, string $_format): array
|
||||
public function getContextForSerialization(string $action, Request $request, mixed $entity, string $_format): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
@@ -125,7 +123,7 @@ class CRUDController extends AbstractController
|
||||
*
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function view(Request $request, $id): Response
|
||||
public function view(Request $request, mixed $id): Response
|
||||
{
|
||||
return $this->viewAction('view', $request, $id);
|
||||
}
|
||||
@@ -188,7 +186,7 @@ class CRUDController extends AbstractController
|
||||
*
|
||||
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedHttpException
|
||||
*/
|
||||
protected function checkACL(string $action, $entity)
|
||||
protected function checkACL(string $action, mixed $entity)
|
||||
{
|
||||
$this->denyAccessUnlessGranted($this->getRoleFor($action), $entity);
|
||||
}
|
||||
@@ -228,7 +226,7 @@ class CRUDController extends AbstractController
|
||||
* @param mixed $entity
|
||||
* @param string $formClass
|
||||
*/
|
||||
protected function createFormFor(string $action, $entity, ?string $formClass = null, array $formOptions = []): FormInterface
|
||||
protected function createFormFor(string $action, mixed $entity, ?string $formClass = null, array $formOptions = []): FormInterface
|
||||
{
|
||||
$formClass ??= $this->getFormClassFor($action);
|
||||
|
||||
@@ -491,7 +489,7 @@ class CRUDController extends AbstractController
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
*/
|
||||
protected function formEditAction(string $action, Request $request, $id, ?string $formClass = null, array $formOptions = []): Response
|
||||
protected function formEditAction(string $action, Request $request, mixed $id, ?string $formClass = null, array $formOptions = []): Response
|
||||
{
|
||||
$entity = $this->getEntity($action, $id, $request);
|
||||
|
||||
@@ -572,29 +570,15 @@ class CRUDController extends AbstractController
|
||||
* Generate a success message when a form could be flushed successfully.
|
||||
*
|
||||
* @param string $action
|
||||
* @param mixed $entity
|
||||
*/
|
||||
protected function generateFormSuccessMessage($action, $entity): string
|
||||
protected function generateFormSuccessMessage($action, mixed $entity): string
|
||||
{
|
||||
switch ($action) {
|
||||
case 'edit':
|
||||
$msg = 'crud.edit.success';
|
||||
|
||||
break;
|
||||
|
||||
case 'new':
|
||||
$msg = 'crud.new.success';
|
||||
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$msg = 'crud.delete.success';
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$msg = 'crud.default.success';
|
||||
}
|
||||
$msg = match ($action) {
|
||||
'edit' => 'crud.edit.success',
|
||||
'new' => 'crud.new.success',
|
||||
'delete' => 'crud.delete.success',
|
||||
default => 'crud.default.success',
|
||||
};
|
||||
|
||||
return $this->getTranslator()->trans($msg);
|
||||
}
|
||||
@@ -652,11 +636,10 @@ class CRUDController extends AbstractController
|
||||
* get the instance of the entity with the given id.
|
||||
*
|
||||
* @param string $id
|
||||
* @param mixed $action
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected function getEntity($action, $id, Request $request): ?object
|
||||
protected function getEntity(mixed $action, $id, Request $request): ?object
|
||||
{
|
||||
return $this->getDoctrine()
|
||||
->getRepository($this->getEntityClass())
|
||||
@@ -763,33 +746,22 @@ class CRUDController extends AbstractController
|
||||
*
|
||||
* @return string the path to the template
|
||||
*/
|
||||
protected function getTemplateFor($action, $entity, Request $request)
|
||||
protected function getTemplateFor($action, mixed $entity, Request $request)
|
||||
{
|
||||
if ($this->hasCustomTemplate($action, $entity, $request)) {
|
||||
return $this->getActionConfig($action)['template'];
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'new':
|
||||
return '@ChillMain/CRUD/new.html.twig';
|
||||
|
||||
case 'edit':
|
||||
return '@ChillMain/CRUD/edit.html.twig';
|
||||
|
||||
case 'index':
|
||||
return '@ChillMain/CRUD/index.html.twig';
|
||||
|
||||
case 'view':
|
||||
return '@ChillMain/CRUD/view.html.twig';
|
||||
|
||||
case 'delete':
|
||||
return '@ChillMain/CRUD/delete.html.twig';
|
||||
|
||||
default:
|
||||
throw new LogicException("the view for action {$action} is not "
|
||||
. 'defined. You should override ' . __METHOD__ . ' to add this '
|
||||
. 'action');
|
||||
}
|
||||
return match ($action) {
|
||||
'new' => '@ChillMain/CRUD/new.html.twig',
|
||||
'edit' => '@ChillMain/CRUD/edit.html.twig',
|
||||
'index' => '@ChillMain/CRUD/index.html.twig',
|
||||
'view' => '@ChillMain/CRUD/view.html.twig',
|
||||
'delete' => '@ChillMain/CRUD/delete.html.twig',
|
||||
default => throw new LogicException("the view for action {$action} is not "
|
||||
. 'defined. You should override ' . __METHOD__ . ' to add this '
|
||||
. 'action'),
|
||||
};
|
||||
}
|
||||
|
||||
protected function getTranslator(): TranslatorInterface
|
||||
@@ -909,22 +881,17 @@ class CRUDController extends AbstractController
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
protected function onBeforeRedirectAfterSubmission(string $action, $entity, FormInterface $form, Request $request)
|
||||
protected function onBeforeRedirectAfterSubmission(string $action, mixed $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
$next = $request->request->get('submit', 'save-and-close');
|
||||
|
||||
switch ($next) {
|
||||
case 'save-and-close':
|
||||
return $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_index');
|
||||
|
||||
case 'save-and-new':
|
||||
return $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_new', $request->query->all());
|
||||
|
||||
default:
|
||||
return $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_view', [
|
||||
'id' => $entity->getId(),
|
||||
]);
|
||||
}
|
||||
return match ($next) {
|
||||
'save-and-close' => $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_index'),
|
||||
'save-and-new' => $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_new', $request->query->all()),
|
||||
default => $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_view', [
|
||||
'id' => $entity->getId(),
|
||||
]),
|
||||
};
|
||||
}
|
||||
|
||||
protected function onFormValid(string $action, object $entity, FormInterface $form, Request $request)
|
||||
@@ -958,19 +925,15 @@ class CRUDController extends AbstractController
|
||||
|
||||
/**
|
||||
* method used by indexAction.
|
||||
*
|
||||
* @param mixed $query
|
||||
*/
|
||||
protected function onPostIndexBuildQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, $query)
|
||||
protected function onPostIndexBuildQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, mixed $query)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* method used by indexAction.
|
||||
*
|
||||
* @param mixed $entities
|
||||
*/
|
||||
protected function onPostIndexFetchQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, $entities)
|
||||
protected function onPostIndexFetchQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, mixed $entities)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1091,7 +1054,7 @@ class CRUDController extends AbstractController
|
||||
* @param mixed $id
|
||||
* @param mixed $_format
|
||||
*/
|
||||
protected function viewAction(string $action, Request $request, $id, $_format = 'html'): Response
|
||||
protected function viewAction(string $action, Request $request, mixed $id, mixed $_format = 'html'): Response
|
||||
{
|
||||
$entity = $this->getEntity($action, $id, $request);
|
||||
|
||||
|
Reference in New Issue
Block a user