Skip to content

Commit

Permalink
Improved code on model Person
Browse files Browse the repository at this point in the history
  • Loading branch information
kreaweb.be committed Jul 31, 2024
1 parent b523e1d commit 797e0b0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/Models/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ protected function getNameAttribute(): ?string

protected function getAgeAttribute(): ?int
{
$age = null;

if ($this->dob) {
if ($this->dod) {
// deceased based on dob & dod
Expand All @@ -185,9 +183,11 @@ protected function getAgeAttribute(): ?int
// living
$age = Carbon::now()->format('Y') - $this->yob;
}
} else {
$age = null;
}

return $age >= 0 ? $age : null;
return $age > 0 ? $age : null;
}

protected function getNextBirthdayAttribute(): ?Carbon
Expand All @@ -214,8 +214,6 @@ protected function getNextBirthdayRemainingDaysAttribute(): ?int

protected function getLifetimeAttribute(): ?string
{
$lifetime = null;

if ($this->dob) {
if ($this->dod) {
// deceased based on dob & dod
Expand All @@ -238,6 +236,8 @@ protected function getLifetimeAttribute(): ?string
// living
$lifetime = strval($this->yob);
}
} else {
$lifetime = null;
}

return $lifetime; //returns YEAR(dob) - YEAR(dod)
Expand Down Expand Up @@ -276,10 +276,10 @@ protected function getBirthFormattedAttribute(): ?string
} elseif ($this->yob) {
$dob = $this->yob;
} else {
$dob = '??';
$dob = null;
}

return strval($dob);
return $dob ? strval($dob) : $dob;
}

protected function getDeathFormattedAttribute(): ?string
Expand All @@ -289,10 +289,10 @@ protected function getDeathFormattedAttribute(): ?string
} elseif ($this->yod) {
$dod = $this->yod;
} else {
$dod = '??';
$dod = null;
}

return strval($dod);
return $dod ? strval($dod) : $dod;
}

protected function getAddressAttribute(): ?string
Expand Down

0 comments on commit 797e0b0

Please sign in to comment.