mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
fix: SA: Fix "...invoked with..." rule.
SA stands for Static Analysis.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\AbstractCRUDController;
|
||||
@@ -7,6 +9,7 @@ use Chill\MainBundle\CRUD\Controller\CRUDController;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -16,40 +19,23 @@ use Chill\MainBundle\Form\UserType;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Form\Type\ComposedGroupCenterType;
|
||||
use Chill\MainBundle\Form\UserPasswordType;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter;
|
||||
|
||||
|
||||
/**
|
||||
* Class UserController
|
||||
*
|
||||
* @package Chill\MainBundle\Controller
|
||||
*/
|
||||
class UserController extends CRUDController
|
||||
{
|
||||
|
||||
const FORM_GROUP_CENTER_COMPOSED = 'composed_groupcenter';
|
||||
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* @var ValidatorInterface
|
||||
*/
|
||||
private $validator;
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
private UserPasswordEncoderInterface $passwordEncoder;
|
||||
|
||||
/**
|
||||
* UserController constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
* @param ValidatorInterface $validator
|
||||
*/
|
||||
public function __construct(
|
||||
LoggerInterface $chillLogger,
|
||||
ValidatorInterface $validator,
|
||||
@@ -121,7 +107,7 @@ class UserController extends CRUDController
|
||||
*/
|
||||
public function editPasswordAction(User $user, Request $request)
|
||||
{
|
||||
$editForm = $this->createEditPasswordForm($user, $request);
|
||||
$editForm = $this->createEditPasswordForm($user);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
@@ -208,7 +194,7 @@ class UserController extends CRUDController
|
||||
* @Route("/{_locale}/admin/main/user/{uid}/add_link_groupcenter",
|
||||
* name="admin_user_add_groupcenter")
|
||||
*/
|
||||
public function addLinkGroupCenterAction(Request $request, $uid): RedirectResponse
|
||||
public function addLinkGroupCenterAction(Request $request, $uid): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
@@ -238,23 +224,22 @@ class UserController extends CRUDController
|
||||
return $this->redirect($this->generateUrl('chill_crud_admin_user_edit',
|
||||
\array_merge(['id' => $uid], $returnPathParams)));
|
||||
|
||||
} else {
|
||||
foreach($this->validator->validate($user) as $error)
|
||||
}
|
||||
|
||||
foreach($this->validator->validate($user) as $error) {
|
||||
$this->addFlash('error', $error->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('@ChillMain/User/edit.html.twig', array(
|
||||
return $this->render('@ChillMain/User/edit.html.twig', [
|
||||
'entity' => $user,
|
||||
'edit_form' => $this->createEditForm($user)->createView(),
|
||||
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user)->createView(),
|
||||
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user, $request)->createView(),
|
||||
'delete_groupcenter_form' => array_map(
|
||||
function(\Symfony\Component\Form\Form $form) {
|
||||
return $form->createView();
|
||||
|
||||
},
|
||||
iterator_to_array($this->getDeleteLinkGroupCenterByUser($user), true))
|
||||
));
|
||||
static fn(Form $form) => $form->createView(),
|
||||
iterator_to_array($this->getDeleteLinkGroupCenterByUser($user, $request), true)
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
private function getPersistedGroupCenter(GroupCenter $groupCenter)
|
||||
@@ -279,10 +264,8 @@ class UserController extends CRUDController
|
||||
* Creates a form to delete a link to a GroupCenter
|
||||
*
|
||||
* @param mixed $permissionsGroup The entity id
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createDeleteLinkGroupCenterForm(User $user, GroupCenter $groupCenter, $request)
|
||||
private function createDeleteLinkGroupCenterForm(User $user, GroupCenter $groupCenter, $request): FormInterface
|
||||
{
|
||||
$returnPathParams = $request->query->has('returnPath') ? ['returnPath' => $request->query->get('returnPath')] : [];
|
||||
|
||||
@@ -291,39 +274,29 @@ class UserController extends CRUDController
|
||||
array_merge($returnPathParams, ['uid' => $user->getId(), 'gcid' => $groupCenter->getId()])))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, array('label' => 'Delete'))
|
||||
->getForm()
|
||||
;
|
||||
->getForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* create a form to add a link to a groupcenter
|
||||
*
|
||||
* @param User $user
|
||||
* @return \Symfony\Component\Form\Form
|
||||
* Create a form to add a link to a groupcenter.
|
||||
*/
|
||||
private function createAddLinkGroupCenterForm(User $user, Request $request)
|
||||
private function createAddLinkGroupCenterForm(User $user, Request $request): FormInterface
|
||||
{
|
||||
$returnPathParams = $request->query->has('returnPath') ? ['returnPath' => $request->query->get('returnPath')] : [];
|
||||
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('admin_user_add_groupcenter',
|
||||
array_merge($returnPathParams, ['uid' => $user->getId()])))
|
||||
->setMethod('POST')
|
||||
->add(self::FORM_GROUP_CENTER_COMPOSED, ComposedGroupCenterType::class)
|
||||
->add('submit', SubmitType::class, array('label' => 'Add a new groupCenter'))
|
||||
->getForm()
|
||||
;
|
||||
->setAction($this->generateUrl('admin_user_add_groupcenter',
|
||||
array_merge($returnPathParams, ['uid' => $user->getId()])))
|
||||
->setMethod('POST')
|
||||
->add(self::FORM_GROUP_CENTER_COMPOSED, ComposedGroupCenterType::class)
|
||||
->add('submit', SubmitType::class, array('label' => 'Add a new groupCenter'))
|
||||
->getForm();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
private function getDeleteLinkGroupCenterByUser(User $user, Request $request)
|
||||
{
|
||||
foreach ($user->getGroupCenters() as $groupCenter) {
|
||||
yield $groupCenter->getId() => $this
|
||||
->createDeleteLinkGroupCenterForm($user, $groupCenter, $request);
|
||||
yield $groupCenter->getId() => $this->createDeleteLinkGroupCenterForm($user, $groupCenter, $request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user