DX: [accompanying period] refactor the getCenters method

Use more portable spl_object_hash for listing different centers
This commit is contained in:
Julien Fastré 2022-11-28 12:24:10 +01:00
parent 74673380aa
commit fc15b85d11
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -53,7 +53,7 @@ use Symfony\Component\Validator\GroupSequenceProviderInterface;
use UnexpectedValueException;
use function in_array;
use function array_key_exists;
use const SORT_REGULAR;
/**
@ -644,16 +644,18 @@ class AccompanyingPeriod implements
public function getCenters(): ?iterable
{
$centers = [];
foreach ($this->getPersons() as $person) {
if (
!in_array($person->getCenter(), $centers ?? [], true)
&& null !== $person->getCenter()
null !== $person->getCenter()
&& !array_key_exists(spl_object_hash($person->getCenter()), $centers)
) {
$centers[] = $person->getCenter();
$centers[spl_object_hash($person->getCenter())] = $person->getCenter();
}
}
return $centers ?? null;
return array_values($centers);
}
/**