diff --git a/src/Entity/Adherent.php b/src/Entity/Adherent.php index 2fefff85d5c..9e73679383d 100644 --- a/src/Entity/Adherent.php +++ b/src/Entity/Adherent.php @@ -2277,7 +2277,7 @@ public function getMissingMembershipYears(): array return []; } - $lastYear = $this->getLastAdherentYearTag(); + $lastYear = $this->getLastMembershipYearFromTags(); if (!$lastYear) { return [date('Y')]; @@ -2508,32 +2508,22 @@ public function hasTag(string $tag): bool return TagEnum::includesTag($tag, $this->tags ?? []); } - public function getLastAdherentYearTag(): ?string + public function getLastMembershipYearFromTags(): ?string { - $allTags = array_map( - fn (int $year) => TagEnum::getAdherentYearTag($year), - array_reverse(range(2022, date('Y'))) - ); - + $adherentTag = null; foreach ($this->tags as $tag) { - if (\in_array($tag, $allTags, true)) { - return $tag; + if (preg_match('/^adherent:a_jour_[\d]{4}/')) { + $adherentTag = $tag; + break; } } - return null; - } - - public function getLastMembershipYearFromTags(): ?string - { - $lastAdherentYearTag = $this->getLastAdherentYearTag(); - - if (!$lastAdherentYearTag) { + if (!$adherentTag) { return null; } $matches = []; - if (preg_match('/^adherent:a_jour_([\d]{4})$/', $lastAdherentYearTag, $matches)) { + if (preg_match('/^adherent:a_jour_([\d]{4})/', $lastAdherentYearTag, $matches)) { return $matches[1]; }