Skip to content

Commit

Permalink
Fix adherent year tag matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Remg committed Oct 31, 2024
1 parent 8a82cea commit cd499a6
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/Entity/Adherent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,7 @@ public function getMissingMembershipYears(): array
return [];
}

$lastYear = $this->getLastAdherentYearTag();
$lastYear = $this->getLastMembershipYearFromTags();

if (!$lastYear) {
return [date('Y')];
Expand Down Expand Up @@ -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}/', $tag)) {
$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})/', $adherentTag, $matches)) {
return $matches[1];
}

Expand Down

0 comments on commit cd499a6

Please sign in to comment.