Fixes phpstan

This commit is contained in:
Julie Lenaerts 2024-10-01 15:51:45 +02:00
parent e6102d339b
commit 6781fdbd9b
7 changed files with 28 additions and 45 deletions

View File

@ -5,6 +5,7 @@ namespace Chill\MainBundle\Entity;
use Chill\MainBundle\Repository\GenderRepository; use Chill\MainBundle\Repository\GenderRepository;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
#[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['chill_main_gender' => Gender::class])] #[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['chill_main_gender' => Gender::class])]
#[ORM\Entity(repositoryClass: GenderRepository::class)] #[ORM\Entity(repositoryClass: GenderRepository::class)]

View File

@ -34,7 +34,7 @@ class GenderType extends AbstractType
'multiple' => false, 'multiple' => false,
'mapped' => true, 'mapped' => true,
'choice_label' => fn(GenderIconEnum $enum) => '<i class="' . strtolower($enum->value) . '"></i>', 'choice_label' => fn(GenderIconEnum $enum) => '<i class="' . strtolower($enum->value) . '"></i>',
'choice_value' => fn(?GenderIconEnum $enum) => $enum ? $enum->value : null, 'choice_value' => fn(?GenderIconEnum $enum) => null !== $enum ? $enum->value : null,
'label' => 'gender.admin.Select Gender Icon', 'label' => 'gender.admin.Select Gender Icon',
'label_html' => true, 'label_html' => true,
]) ])

View File

@ -1014,7 +1014,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* *
* @deprecated Keep for legacy. Used in Chill 1.5 for feminize before icu translations * @deprecated Keep for legacy. Used in Chill 1.5 for feminize before icu translations
*/ */
public function getGenderNumeric() /* public function getGenderNumeric()
{ {
return match ($this->getGender()) { return match ($this->getGender()) {
self::FEMALE_GENDER => 1, self::FEMALE_GENDER => 1,
@ -1022,7 +1022,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
self::BOTH_GENDER => 2, self::BOTH_GENDER => 2,
default => -1, default => -1,
}; };
} }*/
public function getHouseholdAddresses(): Collection public function getHouseholdAddresses(): Collection
{ {

View File

@ -12,6 +12,8 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\GenderRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
@ -20,7 +22,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
final readonly class GenderAggregator implements AggregatorInterface 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 public function addRole(): ?string
{ {
@ -48,30 +50,16 @@ final readonly class GenderAggregator implements AggregatorInterface
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {
return function ($value) { return function (int|string|null $value) {
switch ($value) { if (null === $value || '' === $value) {
case Person::FEMALE_GENDER: return '';
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));
} }
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; 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\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; 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\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@ -26,14 +31,8 @@ class GenderFilter implements
ExportElementValidatedInterface, ExportElementValidatedInterface,
FilterInterface FilterInterface
{ {
/** public function __construct(private TranslatorInterface $translator, private TranslatableStringHelperInterface $translatableStringHelper)
* @var TranslatorInterface
*/
protected $translator;
public function __construct(TranslatorInterface $translator)
{ {
$this->translator = $translator;
} }
public function addRole(): ?string public function addRole(): ?string
@ -72,14 +71,9 @@ class GenderFilter implements
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder->add('accepted_genders', ChoiceType::class, [ $builder->add('accepted_genders', EntityType::class, [
'choices' => [ 'class' => Gender::class,
'Woman' => Person::FEMALE_GENDER, 'choice_label' => fn(Gender $g) => $this->translatableStringHelper->localize($g->getLabel()),
'Man' => Person::MALE_GENDER,
'Both' => Person::BOTH_GENDER,
'Unknown' => Person::NO_INFORMATION,
'Not given' => 'null',
],
'multiple' => true, 'multiple' => true,
'expanded' => true, 'expanded' => true,
]); ]);
@ -98,7 +92,7 @@ class GenderFilter implements
if ('null' === $g) { if ('null' === $g) {
$genders[] = $this->translator->trans('Not given'); $genders[] = $this->translator->trans('Not given');
} else { } else {
$genders[] = $this->translator->trans($g); $genders[] = $this->translatableStringHelper($g->getLabel());
} }
} }

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Search; namespace Chill\PersonBundle\Search;
use Chill\MainBundle\Form\GenderType;
use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillPhoneNumberType; use Chill\MainBundle\Form\Type\ChillPhoneNumberType;
use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Pagination\PaginatorFactory;
@ -21,7 +22,6 @@ use Chill\MainBundle\Search\SearchInterface;
use Chill\MainBundle\Search\Utils\ExtractDateFromPattern; use Chill\MainBundle\Search\Utils\ExtractDateFromPattern;
use Chill\MainBundle\Search\Utils\ExtractPhonenumberFromPattern; use Chill\MainBundle\Search\Utils\ExtractPhonenumberFromPattern;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Form\Type\GenderType;
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface; use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
use libphonenumber\PhoneNumber; use libphonenumber\PhoneNumber;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;

View File

@ -94,7 +94,7 @@ class PersonDocGenNormalizer implements
'age' => (int) $person->getAge(), 'age' => (int) $person->getAge(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $dateContext), 'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $dateContext),
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $dateContext), 'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $dateContext),
'gender' => $this->translator->trans($person->getGender()), 'gender' => $this$this->translator->trans($person->getGender()),
'maritalStatus' => null !== ($ms = $person->getMaritalStatus()) ? $this->translatableStringHelper->localize($ms->getName()) : '', 'maritalStatus' => null !== ($ms = $person->getMaritalStatus()) ? $this->translatableStringHelper->localize($ms->getName()) : '',
'maritalStatusDate' => $this->normalizer->normalize($person->getMaritalStatusDate(), $format, $dateContext), 'maritalStatusDate' => $this->normalizer->normalize($person->getMaritalStatusDate(), $format, $dateContext),
'maritalStatusComment' => $this->normalizer->normalize($person->getMaritalStatusComment(), $format, $dateContext), 'maritalStatusComment' => $this->normalizer->normalize($person->getMaritalStatusComment(), $format, $dateContext),