Fixes phpstan

This commit is contained in:
2024-10-01 15:51:45 +02:00
parent 77ece243c0
commit 052e09cf64
7 changed files with 28 additions and 45 deletions

View File

@@ -12,6 +12,8 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\GenderRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
@@ -20,7 +22,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
final readonly class GenderAggregator implements AggregatorInterface
{
public function __construct(private TranslatorInterface $translator) {}
public function __construct(private TranslatorInterface $translator, private TranslatableStringHelperInterface $translatableStringHelper, GenderRepository $repository) {}
public function addRole(): ?string
{
@@ -48,30 +50,16 @@ final readonly class GenderAggregator implements AggregatorInterface
public function getLabels($key, array $values, $data)
{
return function ($value) {
switch ($value) {
case Person::FEMALE_GENDER:
return $this->translator->trans('woman');
case Person::MALE_GENDER:
return $this->translator->trans('man');
case Person::BOTH_GENDER:
return $this->translator->trans('both');
case Person::NO_INFORMATION:
return $this->translator->trans('unknown');
case null:
case '':
return $this->translator->trans('Not given');
case '_header':
return $this->translator->trans('Gender');
default:
throw new \LogicException(sprintf('The value %s is not valid', $value));
return function (int|string|null $value) {
if (null === $value || '' === $value) {
return '';
}
if ('_header' === $value) {
return $this->translator->trans('Gender');
}
return (string) $this->translatableStringHelper->localize($this->repository->find((int) $value)?->getLabel());
};
}

View File

@@ -11,13 +11,18 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Entity\GenderEnum;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -26,14 +31,8 @@ class GenderFilter implements
ExportElementValidatedInterface,
FilterInterface
{
/**
* @var TranslatorInterface
*/
protected $translator;
public function __construct(TranslatorInterface $translator)
public function __construct(private TranslatorInterface $translator, private TranslatableStringHelperInterface $translatableStringHelper)
{
$this->translator = $translator;
}
public function addRole(): ?string
@@ -72,14 +71,9 @@ class GenderFilter implements
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('accepted_genders', ChoiceType::class, [
'choices' => [
'Woman' => Person::FEMALE_GENDER,
'Man' => Person::MALE_GENDER,
'Both' => Person::BOTH_GENDER,
'Unknown' => Person::NO_INFORMATION,
'Not given' => 'null',
],
$builder->add('accepted_genders', EntityType::class, [
'class' => Gender::class,
'choice_label' => fn(Gender $g) => $this->translatableStringHelper->localize($g->getLabel()),
'multiple' => true,
'expanded' => true,
]);
@@ -98,7 +92,7 @@ class GenderFilter implements
if ('null' === $g) {
$genders[] = $this->translator->trans('Not given');
} else {
$genders[] = $this->translator->trans($g);
$genders[] = $this->translatableStringHelper($g->getLabel());
}
}