DX: ensure that the return type is correct in ListPersonHelper

This commit is contained in:
Julien Fastré 2022-10-26 14:58:28 +02:00
parent cf7d0c1bdb
commit 4e55f1ede7

View File

@ -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;
};
}
}