diff --git a/src/Bundle/ChillMainBundle/Export/AggregatorInterface.php b/src/Bundle/ChillMainBundle/Export/AggregatorInterface.php index 8840400b6..126b7580b 100644 --- a/src/Bundle/ChillMainBundle/Export/AggregatorInterface.php +++ b/src/Bundle/ChillMainBundle/Export/AggregatorInterface.php @@ -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 */ - public function getQueryKeys($data); + public function getQueryKeys(array $data): array; } diff --git a/src/Bundle/ChillMainBundle/Export/ExportElementInterface.php b/src/Bundle/ChillMainBundle/Export/ExportElementInterface.php index 49b2500f0..e8018bb1a 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportElementInterface.php +++ b/src/Bundle/ChillMainBundle/Export/ExportElementInterface.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace Chill\MainBundle\Export; +use Symfony\Contracts\Translation\TranslatableInterface; + /** * The common methods between different object used to build export (i.e. : ExportInterface, * FilterInterface, AggregatorInterface). @@ -19,8 +21,6 @@ interface ExportElementInterface { /** * get a title, which will be used in UI (and translated). - * - * @return string */ - public function getTitle(); + public function getTitle(): string|TranslatableInterface; } diff --git a/src/Bundle/ChillMainBundle/Export/ExportElementValidatedInterface.php b/src/Bundle/ChillMainBundle/Export/ExportElementValidatedInterface.php index d4f58a570..d5c5b435c 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportElementValidatedInterface.php +++ b/src/Bundle/ChillMainBundle/Export/ExportElementValidatedInterface.php @@ -31,5 +31,5 @@ interface ExportElementValidatedInterface * validate the form's data and, if required, build a contraint * violation on the data. */ - public function validateForm(mixed $data, ExecutionContextInterface $context); + public function validateForm(mixed $data, ExecutionContextInterface $context): void; } diff --git a/src/Bundle/ChillMainBundle/Export/ExportElementsProviderInterface.php b/src/Bundle/ChillMainBundle/Export/ExportElementsProviderInterface.php index 43e0e506a..f92e9bd50 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportElementsProviderInterface.php +++ b/src/Bundle/ChillMainBundle/Export/ExportElementsProviderInterface.php @@ -21,7 +21,7 @@ namespace Chill\MainBundle\Export; interface ExportElementsProviderInterface { /** - * @return ExportElementInterface[] + * @return iterable */ - public function getExportElements(); + public function getExportElements(): iterable; } diff --git a/src/Bundle/ChillMainBundle/Export/ExportInterface.php b/src/Bundle/ChillMainBundle/Export/ExportInterface.php index 9dbf0ae73..a44aa681b 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportInterface.php +++ b/src/Bundle/ChillMainBundle/Export/ExportInterface.php @@ -14,6 +14,7 @@ namespace Chill\MainBundle\Export; use Doctrine\ORM\NativeQuery; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Contracts\Translation\TranslatableInterface; /** * Interface for Export. @@ -27,6 +28,7 @@ use Symfony\Component\Form\FormBuilderInterface; * @example Chill\PersonBundle\Export\CountPerson an example of implementation * * @template Q of QueryBuilder|NativeQuery + * @tempalte D of array */ interface ExportInterface extends ExportElementInterface { @@ -95,9 +97,9 @@ interface ExportInterface extends ExportElementInterface * database. But the header must be, in every case, translated. * * @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') + * @param list $values The values from the result. if there are duplicates, those might be given twice. Example: array('FR', 'BE', 'CZ', 'FR', 'BE', 'FR') * - * @return (callable(string|int|float|'_header'|null $value): string|int|\DateTimeInterface) 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); @@ -108,29 +110,27 @@ interface ExportInterface extends ExportElementInterface * 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) */ - public function getQueryKeys($data); + public function getQueryKeys(array $data): array; /** * Return the results of the query builder. * * @param Q $query - * @param mixed[] $data the data from the export's fomr (added by self::buildForm) + * @param D $data the data from the export's fomr (added by self::buildForm) * * @return mixed[] an array of results */ - public function getResult($query, $data, ExportGenerationContext $context); + public function getResult(QueryBuilder|NativeQuery $query, array $data, ExportGenerationContext $context): array; /** * Return the Export's type. This will inform _on what_ export will apply. * Most of the type, it will be a string which references an entity. * * Example of types : Chill\PersonBundle\Export\Declarations::PERSON_TYPE - * - * @return string */ - public function getType(); + public function getType(): string; /** * The initial query, which will be modified by ModifiersInterface @@ -147,10 +147,19 @@ interface ExportInterface extends ExportElementInterface * * @return Q the query to execute */ - public function initiateQuery(array $requiredModifiers, array $acl, array $data, ExportGenerationContext $context); + public function initiateQuery(array $requiredModifiers, array $acl, array $data, ExportGenerationContext $context): QueryBuilder|NativeQuery; + /** + * @param D $formData + * @return array + */ public function normalizeFormData(array $formData): array; + /** + * @param array $formData the normalized data + * @param int $fromVersion + * @return D + */ public function denormalizeFormData(array $formData, int $fromVersion): array; public function getNormalizationVersion(): int; diff --git a/src/Bundle/ChillMainBundle/Export/FilterInterface.php b/src/Bundle/ChillMainBundle/Export/FilterInterface.php index 46cc6dea5..94f025dcd 100644 --- a/src/Bundle/ChillMainBundle/Export/FilterInterface.php +++ b/src/Bundle/ChillMainBundle/Export/FilterInterface.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Export; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Contracts\Translation\TranslatableInterface; /** * Interface for filters. @@ -20,6 +21,8 @@ use Symfony\Component\Form\FormBuilderInterface; * it will add a `WHERE` clause on this query. * * Filters should not add column in `SELECT` clause. + * + * @template D of array */ interface FilterInterface extends ModifierInterface { @@ -28,18 +31,29 @@ interface FilterInterface 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. * * In case of adding new parameters to a filter, you can implement a @see{DataTransformerFilterInterface} to * transforme the filters's data saved in an export to the desired state. + * + * @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; @@ -58,7 +72,7 @@ interface FilterInterface extends ModifierInterface * supported, later some 'html' will be added. The filter should always * implement the 'string' format and fallback to it if other format are used. * - * If no i18n is necessery, or if the filter translate the string by himself, + * If no i18n is necessary, or if the filter translate the string by himself, * this function should return a string. If the filter does not do any translation, * the return parameter should be an array, where * @@ -69,10 +83,9 @@ interface FilterInterface extends ModifierInterface * * Example: `array('my string with %parameter%', ['%parameter%' => 'good news'], 'mydomain', 'mylocale')` * - * @param array $data - * @param string $format the format + * @param D $data * - * @return array|string a string with the data or, if translatable, an array where first element is string, second elements is an array of arguments + * @return array|string|TranslatableInterface a string with the data or, if translatable, an array where first element is string, second elements is an array of arguments */ - public function describeAction($data, $format = 'string'); + public function describeAction(array $data): array|string|TranslatableInterface; } diff --git a/src/Bundle/ChillMainBundle/Export/FormatterInterface.php b/src/Bundle/ChillMainBundle/Export/FormatterInterface.php index 9f140ebff..41c08ae37 100644 --- a/src/Bundle/ChillMainBundle/Export/FormatterInterface.php +++ b/src/Bundle/ChillMainBundle/Export/FormatterInterface.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Export; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Contracts\Translation\TranslatableInterface; /** * @method generate($result, $formatterData, string $exportAlias, array $exportData, array $filtersData, array $aggregatorsData): FormattedExportGeneration @@ -33,16 +34,16 @@ interface FormatterInterface */ public function buildForm( FormBuilderInterface $builder, - $exportAlias, + string $exportAlias, array $aggregatorAliases, - ); + ): void; /** * get the default data for the form build by buildForm. */ public function getFormDefaultData(array $aggregatorAliases): array; - public function getName(); + public function getName(): string|TranslatableInterface; /** * Generate a response from the data collected on differents ExportElementInterface. @@ -54,6 +55,8 @@ interface FormatterInterface * @param array $aggregatorsData an array containing the aggregators data. The key are the filters id, and the value are the data * * @return \Symfony\Component\HttpFoundation\Response The response to be shown + * + * @deprecated use generate instead */ public function getResponse( $result, @@ -64,7 +67,7 @@ interface FormatterInterface array $aggregatorsData, ); - public function getType(); + public function getType(): string; public function normalizeFormData(array $formData): array; diff --git a/src/Bundle/ChillMainBundle/Export/ModifierInterface.php b/src/Bundle/ChillMainBundle/Export/ModifierInterface.php index 0cbc8dd77..9596e026b 100644 --- a/src/Bundle/ChillMainBundle/Export/ModifierInterface.php +++ b/src/Bundle/ChillMainBundle/Export/ModifierInterface.php @@ -36,15 +36,13 @@ interface ModifierInterface extends ExportElementInterface * * @param QueryBuilder $qb the QueryBuilder initiated by the Export (and eventually modified by other Modifiers) * @param mixed[] $data the data from the Form (builded by buildForm) - * - * @return void */ - public function alterQuery(QueryBuilder $qb, $data, ExportGenerationContext $exportGenerationContext); + public function alterQuery(QueryBuilder $qb, $data, ExportGenerationContext $exportGenerationContext): void; /** * On which type of Export this ModifiersInterface may apply. * * @return string the type on which the Modifiers apply */ - public function applyOn(); + public function applyOn(): string; }