From 4e55f1ede77cac731d77fcfc515733d37b95400f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 26 Oct 2022 14:58:28 +0200 Subject: [PATCH] DX: ensure that the return type is correct in ListPersonHelper --- .../Export/Helper/ListPersonHelper.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Helper/ListPersonHelper.php b/src/Bundle/ChillPersonBundle/Export/Helper/ListPersonHelper.php index 7a14e0446..69f797c3d 100644 --- a/src/Bundle/ChillPersonBundle/Export/Helper/ListPersonHelper.php +++ b/src/Bundle/ChillPersonBundle/Export/Helper/ListPersonHelper.php @@ -25,6 +25,7 @@ use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; use Exception; use PhpOffice\PhpSpreadsheet\Shared\Date; +use RuntimeException; use Symfony\Contracts\Translation\TranslatorInterface; use function in_array; use function strlen; @@ -390,16 +391,18 @@ class ListPersonHelper }; default: - // for fields which are associated with person - if (in_array($key, ListPersonHelper::FIELDS, true)) { - return function ($value) use ($key) { - if ('_header' === $value) { - return $this->translator->trans($key); - } - - return $value; - }; + if (!in_array($key, self::getAllPossibleFields(), true)) { + throw new RuntimeException("this key is not supported by this helper: {$key}"); } + + // for fields which are associated with person + return function ($value) use ($key) { + if ('_header' === $value) { + return $this->translator->trans($key); + } + + return $value; + }; } }