From 9ce1788a14dc648432b29d0513701c001e2f7ab2 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 22 May 2024 16:42:47 +0200 Subject: [PATCH] phpstan en rector fixes --- .../CustomFields/CustomFieldInterface.php | 4 - .../CustomFields/CustomFieldsChoiceTest.php | 2 - .../Controller/EventTypeController.php | 1 - .../Controller/RoleController.php | 1 - .../Controller/StatusController.php | 1 - .../ApiHelper/PartenaireRomeAppellation.php | 6 +- .../DependencyInjection/ChillJobExtension.php | 3 - .../Export/AddCSPersonToPersonListHelper.php | 143 ++++++++---------- .../CRUD/Controller/CRUDController.php | 2 - .../Controller/PermissionsGroupController.php | 2 - .../Export/AggregatorInterface.php | 1 - .../ExportElementValidatedInterface.php | 2 - .../Export/ExportInterface.php | 1 - .../ChillMainBundle/Export/ExportManager.php | 6 - .../ChillMainBundle/Search/SearchProvider.php | 6 +- .../Authorization/AuthorizationHelper.php | 1 - 16 files changed, 75 insertions(+), 107 deletions(-) diff --git a/src/Bundle/ChillCustomFieldsBundle/CustomFields/CustomFieldInterface.php b/src/Bundle/ChillCustomFieldsBundle/CustomFields/CustomFieldInterface.php index 7ba5cff74..2f4cfd1e4 100644 --- a/src/Bundle/ChillCustomFieldsBundle/CustomFields/CustomFieldInterface.php +++ b/src/Bundle/ChillCustomFieldsBundle/CustomFields/CustomFieldInterface.php @@ -49,17 +49,13 @@ interface CustomFieldInterface /** * Return if the value can be considered as empty. - * - * @param mixed $value the value passed throug the deserialize function */ public function isEmptyValue(mixed $value, CustomField $customField); /** * Return a repsentation of the value of the CustomField. * - * @param mixed $value the raw value, **not deserialized** (= as stored in the db) * @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField - * * @return string an html representation of the value */ public function render(mixed $value, CustomField $customField, $documentType = 'html'); diff --git a/src/Bundle/ChillCustomFieldsBundle/Tests/CustomFields/CustomFieldsChoiceTest.php b/src/Bundle/ChillCustomFieldsBundle/Tests/CustomFields/CustomFieldsChoiceTest.php index b9d00d052..6f6ba394e 100644 --- a/src/Bundle/ChillCustomFieldsBundle/Tests/CustomFields/CustomFieldsChoiceTest.php +++ b/src/Bundle/ChillCustomFieldsBundle/Tests/CustomFields/CustomFieldsChoiceTest.php @@ -399,8 +399,6 @@ final class CustomFieldsChoiceTest extends KernelTestCase /** * @dataProvider emptyDataProvider - * - * @param mixed $data deserialized data */ public function testIsEmptyValueEmpty(mixed $data) { diff --git a/src/Bundle/ChillEventBundle/Controller/EventTypeController.php b/src/Bundle/ChillEventBundle/Controller/EventTypeController.php index 881f7a135..d5ea7901b 100644 --- a/src/Bundle/ChillEventBundle/Controller/EventTypeController.php +++ b/src/Bundle/ChillEventBundle/Controller/EventTypeController.php @@ -201,7 +201,6 @@ class EventTypeController extends AbstractController /** * Creates a form to delete a EventType entity by id. * - * @param mixed $id The entity id * * @return \Symfony\Component\Form\Form The form */ diff --git a/src/Bundle/ChillEventBundle/Controller/RoleController.php b/src/Bundle/ChillEventBundle/Controller/RoleController.php index e1d94389a..fe6c60a85 100644 --- a/src/Bundle/ChillEventBundle/Controller/RoleController.php +++ b/src/Bundle/ChillEventBundle/Controller/RoleController.php @@ -201,7 +201,6 @@ class RoleController extends AbstractController /** * Creates a form to delete a Role entity by id. * - * @param mixed $id The entity id * * @return \Symfony\Component\Form\Form The form */ diff --git a/src/Bundle/ChillEventBundle/Controller/StatusController.php b/src/Bundle/ChillEventBundle/Controller/StatusController.php index 77f6d4279..446fb476e 100644 --- a/src/Bundle/ChillEventBundle/Controller/StatusController.php +++ b/src/Bundle/ChillEventBundle/Controller/StatusController.php @@ -201,7 +201,6 @@ class StatusController extends AbstractController /** * Creates a form to delete a Status entity by id. * - * @param mixed $id The entity id * * @return \Symfony\Component\Form\Form The form */ diff --git a/src/Bundle/ChillFranceTravailApiBundle/src/ApiHelper/PartenaireRomeAppellation.php b/src/Bundle/ChillFranceTravailApiBundle/src/ApiHelper/PartenaireRomeAppellation.php index 533e8d274..5c32033ad 100644 --- a/src/Bundle/ChillFranceTravailApiBundle/src/ApiHelper/PartenaireRomeAppellation.php +++ b/src/Bundle/ChillFranceTravailApiBundle/src/ApiHelper/PartenaireRomeAppellation.php @@ -16,6 +16,7 @@ use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Utils; use Psr\Log\LoggerInterface; +use Symfony\Component\HttpFoundation\Response; /** * Queries for ROME partenaires api. @@ -81,11 +82,14 @@ class PartenaireRomeAppellation $this->client, $this->logger ); + + return Utils::jsonDecode((string) $response->getBody()); + } catch (ClientException $e) { dump($e->getResponse()->getBody()->getContents()); } - return Utils::jsonDecode((string) $response->getBody()); + return new Response('No appellation found'); } public function getAppellation($code) diff --git a/src/Bundle/ChillJobBundle/src/DependencyInjection/ChillJobExtension.php b/src/Bundle/ChillJobBundle/src/DependencyInjection/ChillJobExtension.php index 165b5e557..110e5d8df 100644 --- a/src/Bundle/ChillJobBundle/src/DependencyInjection/ChillJobExtension.php +++ b/src/Bundle/ChillJobBundle/src/DependencyInjection/ChillJobExtension.php @@ -51,9 +51,6 @@ class ChillJobExtension extends Extension implements PrependExtensionInterface $loader->load('services/export.yml'); $loader->load('services/menu.yml'); $loader->load('services/security.yml'); - - // exports: list_CSperson override list_person - $container->setAlias('chill.person.export.list_person', \Chill\JobBundle\Export\ListCSPerson::class); } public function prepend(ContainerBuilder $container): void diff --git a/src/Bundle/ChillJobBundle/src/Export/AddCSPersonToPersonListHelper.php b/src/Bundle/ChillJobBundle/src/Export/AddCSPersonToPersonListHelper.php index 5436158f6..4d53722c0 100644 --- a/src/Bundle/ChillJobBundle/src/Export/AddCSPersonToPersonListHelper.php +++ b/src/Bundle/ChillJobBundle/src/Export/AddCSPersonToPersonListHelper.php @@ -113,85 +113,76 @@ class AddCSPersonToPersonListHelper implements CustomizeListPersonHelperInterfac public function getLabels(string $key, array $values, array $data): ?callable { - switch ($key) { - case str_contains($key, '__'): - return function (string|bool|null $value) use ($key): string { - if ('_header' === $value) { - [$domain, $v] = explode('__', $key); + if (str_contains($key, '__')) + { + return function (string|bool|null $value) use ($key): string { + if ('_header' === $value) { + [$domain, $v] = explode('__', $key); - return 'export.list.cs_person.'.$domain.'.'.$v; - } + return 'export.list.cs_person.'.$domain.'.'.$v; + } - if ('1' === $value || true === $value || 1 === $value || 't' === $value) { - return 'x'; - } + if ('1' === $value || true === $value || 't' === $value) { + return 'x'; + } - return ''; - }; - case 'nEETEligibilite': - return function (string|bool|null $value): string { - if ('_header' === $value) { - return 'export.list.cs_person.neet_eligibility'; - } - - if ('1' === $value || true === $value || 1 === $value || 't' === $value) { - return 'x'; - } - - return ''; - }; - case 'situationProfessionnelle': - return function ($value) { - if ('_header' === $value) { - return 'export.list.cs_person.situation_professionelle'; - } - - return $value; - }; - case 'cerinscriptiondate': - case 'ppaeinscriptiondate': - case 'neetcommissiondate': - case 'findernieremploidate': - case 'cafinscriptiondate': - case 'contratiejdate': - return function ($value) use ($key) { - if ('_header' === $value) { - return $this->translator->trans($key); - } - - if (null === $value) { - return ''; - } - // warning: won't work with DateTimeImmutable as we reset time a few lines later - $date = \DateTime::createFromFormat('Y-m-d', $value); - $hasTime = false; - - if (false === $date) { - $date = \DateTime::createFromFormat('Y-m-d H:i:s', $value); - $hasTime = true; - } - - // check that the creation could occur. - if (false === $date) { - throw new \Exception(sprintf('The value %s could not be converted to %s', $value, \DateTime::class)); - } - - if (!$hasTime) { - $date->setTime(0, 0, 0); - } - - return $date; - }; - - default: - // for fields which are associated with person - return function ($value) use ($key) { - if ('_header' === $value) { - return $this->translator->trans($key); - } - - return $value; - }; + return ''; + }; } + return match ($key) { + 'nEETEligibilite' => function (string|bool|null $value): string { + if ('_header' === $value) { + return 'export.list.cs_person.neet_eligibility'; + } + + if ('1' === $value || true === $value || 't' === $value) { + return 'x'; + } + + return ''; + }, + 'situationProfessionnelle' => function ($value) { + if ('_header' === $value) { + return 'export.list.cs_person.situation_professionelle'; + } + + return $value; + }, + 'cerinscriptiondate', 'ppaeinscriptiondate', 'neetcommissiondate', 'findernieremploidate', 'cafinscriptiondate', 'contratiejdate' => function ($value) use ($key) { + if ('_header' === $value) { + return $this->translator->trans($key); + } + + if (null === $value) { + return ''; + } + // warning: won't work with DateTimeImmutable as we reset time a few lines later + $date = \DateTime::createFromFormat('Y-m-d', $value); + $hasTime = false; + + if (false === $date) { + $date = \DateTime::createFromFormat('Y-m-d H:i:s', $value); + $hasTime = true; + } + + // check that the creation could occur. + if (false === $date) { + throw new \Exception(sprintf('The value %s could not be converted to %s', $value, \DateTime::class)); + } + + if (!$hasTime) { + $date->setTime(0, 0, 0); + } + + return $date; + }, + default => function ($value) use ($key) { + if ('_header' === $value) { + return $this->translator->trans($key); + } + + return $value; + }, + }; } } diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php index f4c9538c7..ada07eb7b 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php @@ -725,10 +725,8 @@ class CRUDController extends AbstractController * and view. * * @param string $action - * @param mixed $entity the entity for the current request, or an array of entities * * @return string the path to the template - * * @throws \LogicException if no template are available */ protected function getTemplateFor($action, mixed $entity, Request $request) diff --git a/src/Bundle/ChillMainBundle/Controller/PermissionsGroupController.php b/src/Bundle/ChillMainBundle/Controller/PermissionsGroupController.php index fc5d7d061..ec28d3040 100644 --- a/src/Bundle/ChillMainBundle/Controller/PermissionsGroupController.php +++ b/src/Bundle/ChillMainBundle/Controller/PermissionsGroupController.php @@ -442,8 +442,6 @@ final class PermissionsGroupController extends AbstractController /** * Creates a form to delete a link to roleScope. - * - * @param mixed $permissionsGroup The entity id */ private function createDeleteRoleScopeForm( PermissionsGroup $permissionsGroup, diff --git a/src/Bundle/ChillMainBundle/Export/AggregatorInterface.php b/src/Bundle/ChillMainBundle/Export/AggregatorInterface.php index 28c168893..e849dec07 100644 --- a/src/Bundle/ChillMainBundle/Export/AggregatorInterface.php +++ b/src/Bundle/ChillMainBundle/Export/AggregatorInterface.php @@ -73,7 +73,6 @@ 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') - * @param mixed $data The data from the export's form (as defined in `buildForm` * * @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(); }` */ diff --git a/src/Bundle/ChillMainBundle/Export/ExportElementValidatedInterface.php b/src/Bundle/ChillMainBundle/Export/ExportElementValidatedInterface.php index ea9094687..d4f58a570 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportElementValidatedInterface.php +++ b/src/Bundle/ChillMainBundle/Export/ExportElementValidatedInterface.php @@ -30,8 +30,6 @@ interface ExportElementValidatedInterface /** * validate the form's data and, if required, build a contraint * violation on the data. - * - * @param mixed $data the data, as returned by the user */ public function validateForm(mixed $data, ExecutionContextInterface $context); } diff --git a/src/Bundle/ChillMainBundle/Export/ExportInterface.php b/src/Bundle/ChillMainBundle/Export/ExportInterface.php index 39e265153..a9d3efd13 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportInterface.php +++ b/src/Bundle/ChillMainBundle/Export/ExportInterface.php @@ -96,7 +96,6 @@ interface ExportInterface extends ExportElementInterface * * @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 mixed $data The data from the export's form (as defined in `buildForm`) * * @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(); }` */ diff --git a/src/Bundle/ChillMainBundle/Export/ExportManager.php b/src/Bundle/ChillMainBundle/Export/ExportManager.php index 159b90b6b..eb59c4ae2 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportManager.php +++ b/src/Bundle/ChillMainBundle/Export/ExportManager.php @@ -552,9 +552,7 @@ class ExportManager * * This function check the acl. * - * @param mixed $data the data under the initial 'filters' data * @param \Chill\MainBundle\Entity\Center[] $centers the picked centers - * * @throw UnauthorizedHttpException if the user is not authorized */ private function handleFilters( @@ -615,9 +613,6 @@ class ExportManager return $usedTypes; } - /** - * @param mixed $data the data from the filter key of the ExportType - */ private function retrieveUsedFilters(mixed $data): iterable { if (null === $data) { @@ -634,7 +629,6 @@ class ExportManager /** * Retrieve the filter used in this export. * - * @param mixed $data the data from the `filters` key of the ExportType * * @return array an array with types */ diff --git a/src/Bundle/ChillMainBundle/Search/SearchProvider.php b/src/Bundle/ChillMainBundle/Search/SearchProvider.php index e239b872d..73c48f4cf 100644 --- a/src/Bundle/ChillMainBundle/Search/SearchProvider.php +++ b/src/Bundle/ChillMainBundle/Search/SearchProvider.php @@ -257,10 +257,10 @@ class SearchProvider $this->mustBeExtracted[] = $matches[0][$key]; // strip parenthesis if ( - '"' === mb_substr((string) $match, 0, 1) - && '"' === mb_substr((string) $match, mb_strlen((string) $match) - 1) + '"' === mb_substr($match, 0, 1) + && '"' === mb_substr($match, mb_strlen($match) - 1) ) { - $match = trim(mb_substr((string) $match, 1, mb_strlen((string) $match) - 2)); + $match = trim(mb_substr($match, 1, mb_strlen($match) - 2)); } $terms[$matches[1][$key]] = $match; } diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php index 9ca1bdc0b..04d9f30f0 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php @@ -198,7 +198,6 @@ class AuthorizationHelper implements AuthorizationHelperInterface * if the entity implements Chill\MainBundle\Entity\HasScopeInterface, * the scope is taken into account. * - * @param mixed $entity the entity may also implement HasScopeInterface * * @return bool true if the user has access */