From c7d00ca9371808074384bdbc8ef81c9b7e92ef09 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jan 2022 14:35:30 +0100 Subject: [PATCH 1/4] chore: Optimize `composer.json`. --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a6f059112..299010513 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ "doctrine/orm": "^2.7", "erusev/parsedown": "^1.7", "graylog2/gelf-php": "^1.5", - "knplabs/knp-menu": "^3.1", "knplabs/knp-menu-bundle": "^3.0", "knplabs/knp-time-bundle": "^1.12", "league/csv": "^9.7.1", @@ -32,6 +31,7 @@ "symfony/css-selector": "^4.4", "symfony/expression-language": "^4.4", "symfony/form": "^4.4", + "symfony/framework-bundle": "^4.4", "symfony/intl": "^4.4", "symfony/mime": "^4.4", "symfony/monolog-bundle": "^3.5", @@ -47,8 +47,7 @@ "symfony/yaml": "^4.4", "twig/extra-bundle": "^3.0", "twig/intl-extra": "^3.0", - "twig/markdown-extra": "^3.3", - "twig/twig": "^3.0" + "twig/markdown-extra": "^3.3" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "^3.3", From f3f5cc550c6570cb0e3a485e4a9f89f5e706d178 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jan 2022 14:40:59 +0100 Subject: [PATCH 2/4] sa: Fix PHPStan issue. --- phpstan-deprecations.neon | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpstan-deprecations.neon b/phpstan-deprecations.neon index 24deda05f..bc372e96b 100644 --- a/phpstan-deprecations.neon +++ b/phpstan-deprecations.neon @@ -859,11 +859,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Security/PasswordRecover/PasswordRecoverEvent.php - - - message: "#^Call to deprecated method setTimeout\\(\\) of class Redis\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Security/PasswordRecover/PasswordRecoverLocker.php - - message: """ From cf588c97c092145638317f0fba210dafaf167697 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jan 2022 14:41:35 +0100 Subject: [PATCH 3/4] cs: Autofix. --- .../Tests/Export/ExportManagerTest.php | 16 ++++++++-------- .../PasswordRecover/TokenManagerTest.php | 3 ++- .../Tests/Form/Type/PickPersonTypeTest.php | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php b/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php index c09385e50..94266077a 100644 --- a/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php @@ -388,7 +388,7 @@ final class ExportManagerTest extends KernelTestCase public function testGetAggregatorNonExistant() { - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $exportManager = $this->createExportManager(); @@ -446,7 +446,7 @@ final class ExportManagerTest extends KernelTestCase public function testGetExportNonExistant() { - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $exportManager = $this->createExportManager(); @@ -485,7 +485,7 @@ final class ExportManagerTest extends KernelTestCase public function testGetFilterNonExistant() { - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $exportManager = $this->createExportManager(); @@ -646,7 +646,7 @@ final class ExportManagerTest extends KernelTestCase public function testNonExistingFormatter() { - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $exportManager = $this->createExportManager(); @@ -668,10 +668,10 @@ final class ExportManagerTest extends KernelTestCase ?UserInterface $user = null ): ExportManager { $localUser = $user ?? self::$container->get( - 'doctrine.orm.entity_manager' - ) - ->getRepository('ChillMainBundle:User') - ->findOneBy(['username' => 'center a_social']); + 'doctrine.orm.entity_manager' + ) + ->getRepository('ChillMainBundle:User') + ->findOneBy(['username' => 'center a_social']); $token = new UsernamePasswordToken($localUser, 'password', 'provider'); $tokenStorage = new TokenStorage(); $tokenStorage->setToken($token); diff --git a/src/Bundle/ChillMainBundle/Tests/Security/PasswordRecover/TokenManagerTest.php b/src/Bundle/ChillMainBundle/Tests/Security/PasswordRecover/TokenManagerTest.php index 294ddceb6..cc10e43cb 100644 --- a/src/Bundle/ChillMainBundle/Tests/Security/PasswordRecover/TokenManagerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Security/PasswordRecover/TokenManagerTest.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Security\PasswordRecover\TokenManager; use DateInterval; use DateTimeImmutable; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use UnexpectedValueException; /** * @internal @@ -57,7 +58,7 @@ final class TokenManagerTest extends KernelTestCase public function testGenerateEmptyUsernameCanonical() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $tokenManager = $this->tokenManager; // set a username, but not a username canonical diff --git a/src/Bundle/ChillPersonBundle/Tests/Form/Type/PickPersonTypeTest.php b/src/Bundle/ChillPersonBundle/Tests/Form/Type/PickPersonTypeTest.php index 5c7942de3..6a9e37531 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Form/Type/PickPersonTypeTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Form/Type/PickPersonTypeTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Form\Type; use Chill\PersonBundle\Form\Type\PickPersonType; +use RuntimeException; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use function count; @@ -52,7 +53,7 @@ final class PickPersonTypeTest extends KernelTestCase */ public function testWithInvalidOptionCenters() { - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->markTestSkipped('need to inject locale into url generator without request'); $this->formFactory From d19c5c9e41c84b9936424096a5b9aeae59863561 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jan 2022 15:07:41 +0100 Subject: [PATCH 4/4] cs: Autofix. --- .../Controller/PersonApiController.php | 78 +++++++++---------- .../Normalizer/PersonJsonNormalizer.php | 10 ++- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php b/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php index 77c0e296d..48e68c5ac 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php @@ -28,17 +28,54 @@ use function array_values; class PersonApiController extends ApiController { private AuthorizationHelper $authorizationHelper; + private ConfigPersonAltNamesHelper $configPersonAltNameHelper; public function __construct( AuthorizationHelper $authorizationHelper, ConfigPersonAltNamesHelper $configPersonAltNameHelper - ) - { + ) { $this->authorizationHelper = $authorizationHelper; $this->configPersonAltNameHelper = $configPersonAltNameHelper; } + /** + * @Route("/api/1.0/person/config/alt_names.{_format}", + * name="chill_person_config_alt_names", + * requirements={ + * "_format": "json" + * } + * ) + */ + public function configAltNames(Request $request, string $_format): Response + { + // TODO: I CANT process php array + $configAltNamesChoices = $this->configPersonAltNameHelper->getChoices(); + dump($configAltNamesChoices); + dump(array_keys($configAltNamesChoices)); + dump(array_values($configAltNamesChoices)); + $keys = []; + + foreach (array_keys($configAltNamesChoices) as $k) { + $keys[] = ['key' => $k]; + } + dump($keys); + $values = []; + + foreach (array_values($configAltNamesChoices) as $v) { + $values[] = ['labels' => $v]; + } + dump($values); + // dump(array_combine($keys, $values)); + + $configAltNames = [ + ['key' => 'jeune_fille', 'labels' => ['fr' => 'Nom de naissance']], + ['key' => 'surnom', 'labels' => ['fr' => 'Surnom']], + ]; + + return $this->json($configAltNames, Response::HTTP_OK, [], ['groups' => ['read']]); + } + public function personAddressApi($id, Request $request, string $_format): Response { return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, ['groups' => ['read']]); @@ -75,41 +112,4 @@ class PersonApiController extends ApiController return $this->json(array_values($addresses), Response::HTTP_OK, [], ['groups' => ['read']]); } - - - /** - * @Route("/api/1.0/person/config/alt_names.{_format}", - * name="chill_person_config_alt_names", - * requirements={ - * "_format": "json" - * } - * ) - */ - public function configAltNames(Request $request, string $_format): Response - { - - // TODO: I CANT process php array - $configAltNamesChoices = $this->configPersonAltNameHelper->getChoices(); - dump($configAltNamesChoices); - dump(array_keys($configAltNamesChoices)); - dump(array_values($configAltNamesChoices)); - $keys = []; - foreach(array_keys($configAltNamesChoices) as $k){ - array_push($keys, ['key' => $k]); - } - dump($keys); - $values = []; - foreach(array_values($configAltNamesChoices) as $v){ - array_push($values, ['labels' => $v]); - } - dump($values); - // dump(array_combine($keys, $values)); - - $configAltNames = [ - ["key" => "jeune_fille", "labels" => ["fr" => "Nom de naissance" ]], - ["key" => "surnom", "labels" => ["fr" => "Surnom" ]] - ]; - return $this->json($configAltNames, Response::HTTP_OK, [], ['groups' => ['read']]); - } - } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index 74955a382..66d41b3f2 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -80,7 +80,7 @@ class PersonJsonNormalizer implements } foreach (['firstName', 'lastName', 'phonenumber', 'mobilenumber', 'gender', - 'birthdate', 'deathdate', 'center', 'altNames'] + 'birthdate', 'deathdate', 'center', 'altNames', ] as $item) { if (!array_key_exists($item, $data)) { continue; @@ -133,8 +133,11 @@ class PersonJsonNormalizer implements break; case 'altNames': - foreach($data[$item] as $altName){ - $oldAltName = $person->getAltNames()->filter(function (PersonAltName $n) use ($altName) { return $n->getKey() === $altName['key']; })->first(); + foreach ($data[$item] as $altName) { + $oldAltName = $person + ->getAltNames() + ->filter(static fn (PersonAltName $n): bool => $n->getKey() === $altName['key'])->first(); + if (false === $oldAltName) { $newAltName = new PersonAltName(); $newAltName->setKey($altName['key']); @@ -144,6 +147,7 @@ class PersonJsonNormalizer implements $oldAltName->setLabel($altName['label']); } } + break; default: