apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -19,7 +19,6 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormInterface;
@@ -30,9 +29,6 @@ use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
use function array_merge;
class CRUDController extends AbstractController
{
/**
@@ -47,9 +43,6 @@ class CRUDController extends AbstractController
return new Response($parameter);
}
/**
* @param $id
*/
public function delete(Request $request, $id): Response
{
return $this->deleteAction('delete', $request, $id);
@@ -75,7 +68,7 @@ class CRUDController extends AbstractController
public static function getSubscribedServices(): array
{
return array_merge(
return \array_merge(
parent::getSubscribedServices(),
[
'chill_main.paginator_factory' => PaginatorFactory::class,
@@ -178,7 +171,6 @@ class CRUDController extends AbstractController
* Throw an \Symfony\Component\Security\Core\Exception\AccessDeniedHttpException
* if not accessible.
*
*
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedHttpException
*/
protected function checkACL(string $action, mixed $entity)
@@ -189,7 +181,7 @@ class CRUDController extends AbstractController
/**
* Count the number of entities.
*/
protected function countEntities(string $action, Request $request, ?FilterOrderHelper $filterOrder = null): int
protected function countEntities(string $action, Request $request, FilterOrderHelper $filterOrder = null): int
{
return $this->buildQueryEntities($action, $request)
->select('COUNT(e)')
@@ -217,10 +209,8 @@ class CRUDController extends AbstractController
*
* It is preferable to override customizeForm instead of overriding
* this method.
*
* @param string $formClass
*/
protected function createFormFor(string $action, mixed $entity, ?string $formClass = null, array $formOptions = []): FormInterface
protected function createFormFor(string $action, mixed $entity, string $formClass = null, array $formOptions = []): FormInterface
{
$formClass ??= $this->getFormClassFor($action);
@@ -239,7 +229,6 @@ class CRUDController extends AbstractController
protected function customizeQuery(string $action, Request $request, $query): void {}
/**
* @param $id
* @param null $formClass
*/
protected function deleteAction(string $action, Request $request, $id, $formClass = null): Response
@@ -255,13 +244,7 @@ class CRUDController extends AbstractController
}
if (null === $entity) {
throw $this->createNotFoundException(
sprintf(
'The %s with id %s is not found',
$this->getCrudName(),
$id
)
);
throw $this->createNotFoundException(sprintf('The %s with id %s is not found', $this->getCrudName(), $id));
}
$response = $this->checkACL($action, $entity);
@@ -300,7 +283,7 @@ class CRUDController extends AbstractController
return $result;
}
return $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_view', ['id' => $entity->getId()]);
return $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_view', ['id' => $entity->getId()]);
}
if ($form->isSubmitted()) {
@@ -321,8 +304,6 @@ class CRUDController extends AbstractController
/**
* Duplicate an entity.
*
* @return mixed
*/
protected function duplicateEntity(string $action, Request $request)
{
@@ -419,7 +400,7 @@ class CRUDController extends AbstractController
return $result;
}
return $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_view', ['id' => $entity->getId()]);
return $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_view', ['id' => $entity->getId()]);
}
if ($form->isSubmitted()) {
@@ -475,20 +456,15 @@ class CRUDController extends AbstractController
* The parameters may be personnalized using `generateTemplateParameter`.
*
* @param class-string $formClass
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
protected function formEditAction(string $action, Request $request, mixed $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);
if (null === $entity) {
throw $this->createNotFoundException(
sprintf(
'The %s with id %s is not found',
$this->getCrudName(),
$id
)
);
throw $this->createNotFoundException(sprintf('The %s with id %s is not found', $this->getCrudName(), $id));
}
$response = $this->checkACL($action, $entity);
@@ -523,7 +499,7 @@ class CRUDController extends AbstractController
return $result;
}
return $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_index');
return $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_index');
}
if ($form->isSubmitted()) {
@@ -574,7 +550,6 @@ class CRUDController extends AbstractController
/**
* Customize template parameters.
*
*
* @return array
*/
protected function generateTemplateParameter(
@@ -588,8 +563,6 @@ class CRUDController extends AbstractController
/**
* Include services.
*
* @return mixed
*/
protected function getActionConfig(string $action)
{
@@ -623,8 +596,6 @@ class CRUDController extends AbstractController
* get the instance of the entity with the given id.
*
* @param string $id
*
* @return object
*/
protected function getEntity(mixed $action, $id, Request $request): ?object
{
@@ -679,15 +650,13 @@ class CRUDController extends AbstractController
/**
* Get the result of the query.
*
* @return mixed
*/
protected function getQueryResult(
string $action,
Request $request,
int $totalItems,
PaginatorInterface $paginator,
?FilterOrderHelper $filterOrder = null
FilterOrderHelper $filterOrder = null
) {
$query = $this->queryEntities($action, $request, $paginator, $filterOrder);
@@ -697,7 +666,7 @@ class CRUDController extends AbstractController
/**
* @return \Chill\MainBundle\Entity\Center[]
*/
protected function getReachableCenters(string $role, ?Scope $scope = null)
protected function getReachableCenters(string $role, Scope $scope = null)
{
return $this->getAuthorizationHelper()
->getReachableCenters($this->getUser(), $role, $scope);
@@ -712,7 +681,7 @@ class CRUDController extends AbstractController
*/
protected function getRoleFor($action)
{
if (array_key_exists('role', $this->getActionConfig($action))) {
if (\array_key_exists('role', $this->getActionConfig($action))) {
return $this->getActionConfig($action)['role'];
}
@@ -727,11 +696,11 @@ class CRUDController extends AbstractController
* and view.
*
* @param string $action
* @param mixed $entity the entity for the current request, or an array of entities
*
* @throws LogicException if no template are available
* @param mixed $entity the entity for the current request, or an array of entities
*
* @return string the path to the template
*
* @throws \LogicException if no template are available
*/
protected function getTemplateFor($action, mixed $entity, Request $request)
{
@@ -745,9 +714,7 @@ class CRUDController extends AbstractController
'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'),
default => throw new \LogicException("the view for action {$action} is not ".'defined. You should override '.__METHOD__.' to add this action'),
};
}
@@ -756,10 +723,6 @@ class CRUDController extends AbstractController
return $this->container->get('translator');
}
/**
* @param $action
* @param $entity
*/
protected function hasCustomTemplate($action, $entity, Request $request): bool
{
return !empty($this->getActionConfig($action)['template']);
@@ -869,9 +832,9 @@ class CRUDController extends AbstractController
$next = $request->request->get('submit', 'save-and-close');
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', [
'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(),
]),
};
@@ -879,27 +842,16 @@ class CRUDController extends AbstractController
protected function onFormValid(string $action, object $entity, FormInterface $form, Request $request) {}
/**
* @param $action
* @param $entity
*/
protected function onPostCheckACL($action, Request $request, $entity): ?Response
{
return null;
}
/**
* @param $action
* @param $entity
*/
protected function onPostFetchEntity($action, Request $request, $entity): ?Response
{
return null;
}
/**
* @param $entity
*/
protected function onPostFlush(string $action, $entity, FormInterface $form, Request $request) {}
/**
@@ -912,21 +864,12 @@ class CRUDController extends AbstractController
*/
protected function onPostIndexFetchQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, mixed $entities) {}
/**
* @param $entity
*/
protected function onPostPersist(string $action, $entity, FormInterface $form, Request $request) {}
/**
* @param $entity
*/
protected function onPostRemove(string $action, $entity, FormInterface $form, Request $request) {}
protected function onPreDelete(string $action, Request $request) {}
/**
* @param $entity
*/
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request) {}
protected function onPreIndex(string $action, Request $request) {}
@@ -936,14 +879,8 @@ class CRUDController extends AbstractController
*/
protected function onPreIndexBuildQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator) {}
/**
* @param $entity
*/
protected function onPrePersist(string $action, $entity, FormInterface $form, Request $request) {}
/**
* @param $entity
*/
protected function onPreRemove(string $action, $entity, FormInterface $form, Request $request) {}
/**
@@ -969,7 +906,7 @@ class CRUDController extends AbstractController
*
* @return type
*/
protected function queryEntities(string $action, Request $request, PaginatorInterface $paginator, ?FilterOrderHelper $filterOrder = null)
protected function queryEntities(string $action, Request $request, PaginatorInterface $paginator, FilterOrderHelper $filterOrder = null)
{
$query = $this->buildQueryEntities($action, $request)
->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber())
@@ -979,9 +916,6 @@ class CRUDController extends AbstractController
return $this->orderQuery($action, $query, $request, $paginator);
}
/**
* @param $entity
*/
protected function removeEntity(string $action, $entity, FormInterface $form, Request $request)
{
$this->getDoctrine()
@@ -1021,13 +955,7 @@ class CRUDController extends AbstractController
}
if (null === $entity) {
throw $this->createNotFoundException(
sprintf(
'The %s with id %s is not found',
$this->getCrudName(),
$id
)
);
throw $this->createNotFoundException(sprintf('The %s with id %s is not found', $this->getCrudName(), $id));
}
$response = $this->checkACL($action, $entity);