mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 10:03:49 +00:00
Fix phpstan issues
This commit is contained in:
@@ -19,7 +19,7 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
class PersonAltNameDataMapper implements DataMapperInterface
|
||||
{
|
||||
public function mapDataToForms($viewData, iterable $forms)
|
||||
public function mapDataToForms($viewData, iterable $forms): void
|
||||
{
|
||||
if (null === $viewData) {
|
||||
return;
|
||||
@@ -43,11 +43,7 @@ class PersonAltNameDataMapper implements DataMapperInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormInterface[] $forms
|
||||
* @param Collection $viewData
|
||||
*/
|
||||
public function mapFormsToData(iterable $forms, &$viewData)
|
||||
public function mapFormsToData(iterable $forms, &$viewData): void
|
||||
{
|
||||
$mapIndexToKey = [];
|
||||
|
||||
|
@@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Form\ChoiceLoader\PersonChoiceLoader;
|
||||
@@ -25,7 +26,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
@@ -41,46 +41,15 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
* - with the `role` option, only the people belonging to the reachable center for the
|
||||
* given role are displayed.
|
||||
*/
|
||||
class PickPersonType extends AbstractType
|
||||
final class PickPersonType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
* @var PersonRepository
|
||||
*/
|
||||
protected $personRepository;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var UrlGeneratorInterface
|
||||
*/
|
||||
protected $urlGenerator;
|
||||
|
||||
/**
|
||||
* @var \Chill\MainBundle\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
public function __construct(
|
||||
PersonRepository $personRepository,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
UrlGeneratorInterface $urlGenerator,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->personRepository = $personRepository;
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
private readonly PersonRepository $personRepository,
|
||||
private readonly TokenStorageInterface $tokenStorage,
|
||||
private readonly AuthorizationHelper $authorizationHelper,
|
||||
private readonly UrlGeneratorInterface $urlGenerator,
|
||||
private readonly TranslatorInterface $translator
|
||||
) {}
|
||||
|
||||
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
|
||||
{
|
||||
@@ -130,11 +99,16 @@ class PickPersonType extends AbstractType
|
||||
|
||||
protected function filterCentersfom(Options $options)
|
||||
{
|
||||
$user = $this->tokenStorage->getToken()->getUser();
|
||||
if (!$user instanceof User) {
|
||||
throw new \UnexpectedValueException('user should be an instance of '.User::class);
|
||||
}
|
||||
|
||||
if (null === $options['role']) {
|
||||
$centers = array_map(static fn (GroupCenter $g) => $g->getCenter(), $this->user->getGroupCenters()->toArray());
|
||||
$centers = array_map(static fn (GroupCenter $g) => $g->getCenter(), $user->getGroupCenters()->toArray());
|
||||
} else {
|
||||
$centers = $this->authorizationHelper
|
||||
->getReachableCenters($this->user, $options['role']->getRole());
|
||||
->getReachableCenters($user, $options['role']->getRole());
|
||||
}
|
||||
|
||||
if (null === $options['centers']) {
|
||||
|
Reference in New Issue
Block a user