fixup! Add ChillBundle normalization methods rector rule

This commit is contained in:
2025-03-12 21:51:24 +01:00
parent 0609e3f4c3
commit cac7d33a44
16 changed files with 119 additions and 26 deletions

View File

@@ -60,7 +60,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
return $formData;
}
public function denormalizeFormData(array $formData, ExportGenerationContext $context): array
public function denormalizeFormData(array $formData, int $fromVersion): array
{
return $formData;
}

View File

@@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Export;
use Chill\MainBundle\Export\DirectExportInterface;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FormattedExportGeneration;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Doctrine\ORM\EntityManagerInterface;
@@ -21,7 +22,6 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@@ -85,7 +85,7 @@ class ListPersonDuplicate implements DirectExportInterface, ExportElementValidat
return ['precision' => self::PRECISION_DEFAULT_VALUE];
}
public function generate(array $acl, \Chill\MainBundle\Export\ExportGenerationContext $context, array $data = []): Response
public function generate(array $acl, array $data, \Chill\MainBundle\Export\ExportGenerationContext $context): FormattedExportGeneration
{
$values = [];
$values[] = $this->getHeaders();

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickUserLocationType;
use Chill\MainBundle\Repository\LocationRepository;
use Chill\MainBundle\Repository\LocationTypeRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;

View File

@@ -24,10 +24,7 @@ final readonly class CreatorFilter implements FilterInterface
{
use \Chill\MainBundle\Export\ExportDataNormalizerTrait;
function __construct(private readonly UserRepositoryInterface $userRepository)
{
}
public function __construct(private readonly UserRepositoryInterface $userRepository) {}
public function addRole(): ?string
{

View File

@@ -106,6 +106,32 @@ class GeographicalUnitStatFilter implements FilterInterface
]);
}
public function getNormalizationVersion(): int
{
return 1;
}
public function normalizeFormData(array $formData): array
{
return [
'date_calc' => $formData['date_calc']->normalize(),
'units' => array_map(static fn (SimpleGeographicalUnitDTO $unitDTO) => $unitDTO->id, $formData['units']),
];
}
public function denormalizeFormData(array $formData, int $fromVersion): array
{
$units = array_filter(
array_map(
fn (int $id) => $this->geographicalUnitRepository->findSimpleGeographicalUnit($id),
$formData['units'],
),
static fn (?SimpleGeographicalUnitDTO $unitDTO) => null !== $unitDTO,
);
return ['date_calc' => RollingDate::fromNormalized($formData['date_calc']), 'units' => $units];
}
public function getFormDefaultData(): array
{
return ['date_calc' => new RollingDate(RollingDate::T_TODAY)];

View File

@@ -23,7 +23,6 @@ use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\UserHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;

View File

@@ -25,16 +25,21 @@ use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface
final readonly class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface
{
public function __construct(private readonly GeographicalUnitRepositoryInterface $geographicalUnitRepository, private readonly GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly RollingDateConverterInterface $rollingDateConverter) {}
public function __construct(
private GeographicalUnitRepositoryInterface $geographicalUnitRepository,
private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
private TranslatableStringHelperInterface $translatableStringHelper,
private RollingDateConverterInterface $rollingDateConverter,
) {}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
public function alterQuery(QueryBuilder $qb, $data, \Chill\MainBundle\Export\ExportGenerationContext $exportGenerationContext)
{
$subQuery =
'SELECT 1
@@ -88,6 +93,32 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface
]);
}
public function getNormalizationVersion(): int
{
return 1;
}
public function normalizeFormData(array $formData): array
{
return [
'date_calc' => $formData['date_calc']->normalize(),
'units' => array_map(static fn (SimpleGeographicalUnitDTO $unitDTO) => $unitDTO->id, $formData['units']),
];
}
public function denormalizeFormData(array $formData, int $fromVersion): array
{
$units = array_filter(
array_map(
fn (int $id) => $this->geographicalUnitRepository->findSimpleGeographicalUnit($id),
$formData['units'],
),
static fn (?SimpleGeographicalUnitDTO $unitDTO) => null !== $unitDTO,
);
return ['date_calc' => RollingDate::fromNormalized($formData['date_calc']), 'units' => $units];
}
public function getFormDefaultData(): array
{
return ['date_calc' => new RollingDate(RollingDate::T_TODAY)];

View File

@@ -25,10 +25,7 @@ final readonly class CreatorFilter implements FilterInterface
use \Chill\MainBundle\Export\ExportDataNormalizerTrait;
private const PREFIX = 'acpw_filter_creator';
function __construct(private UserRepositoryInterface $userRepository)
{
}
public function __construct(private UserRepositoryInterface $userRepository) {}
public function addRole(): ?string
{

View File

@@ -21,7 +21,6 @@ use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
final readonly class ScopeFilter implements FilterInterface
{