Add explicit return types and TranslatableInterface support

Updated interfaces to include explicit return types for improved type safety and readability. Integrated support for Symfony's TranslatableInterface in relevant methods to enhance translation handling.
This commit is contained in:
2025-04-07 12:56:37 +02:00
parent 2482dcc62e
commit 8331a836f2
8 changed files with 72 additions and 34 deletions

View File

@@ -12,27 +12,41 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatableInterface;
/**
* Interface for Aggregators.
*
* Aggregators gather result of a query. Most of the time, it will add
* a GROUP BY clause.
*
* @template D of array
*/
interface AggregatorInterface extends ModifierInterface
{
/**
* Add a form to collect data from the user.
*/
public function buildForm(FormBuilderInterface $builder);
public function buildForm(FormBuilderInterface $builder): void;
/**
* Get the default data, that can be use as "data" for the form.
*
* @return D
*/
public function getFormDefaultData(): array;
/**
* @param D $formData
* @return array
*/
public function normalizeFormData(array $formData): array;
/**
* @param array $formData
* @param int $fromVersion
* @return D
*/
public function denormalizeFormData(array $formData, int $fromVersion): array;
public function getNormalizationVersion(): int;
@@ -80,7 +94,7 @@ interface AggregatorInterface extends ModifierInterface
* @param string $key The column key, as added in the query
* @param mixed[] $values The values from the result. if there are duplicates, those might be given twice. Example: array('FR', 'BE', 'CZ', 'FR', 'BE', 'FR')
*
* @return \Closure where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }`
* @return (callable(string|int|float|'_header'|null $value): string|int|\DateTimeInterface|TranslatableInterface) where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }`
*/
public function getLabels($key, array $values, mixed $data);
@@ -91,7 +105,8 @@ interface AggregatorInterface extends ModifierInterface
* Example: if your query builder will contains `SELECT count(id) AS count_id ...`,
* this function will return `array('count_id')`.
*
* @param mixed[] $data the data from the export's form (added by self::buildForm)
* @param D $data the data from the export's form (added by self::buildForm)
* @return list<string>
*/
public function getQueryKeys($data);
public function getQueryKeys(array $data): array;
}