mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
DX: [accompanying period] refactor the getCenters method
Use more portable spl_object_hash for listing different centers
This commit is contained in:
parent
74673380aa
commit
fc15b85d11
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user