Skip to content

Commit

Permalink
refactoring by extracting the passedDays() method
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadmp97 committed Sep 17, 2023
1 parent 3139248 commit 42c7255
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 1 addition & 7 deletions app/Listeners/ChallengeAchievementsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ public function __construct(

public function handle($event)
{
$passedDays = $event
->challenge
->continued_at
->diff($event->challenge->created_at)
->d;

$achievement = Achievement::getByPassedDays($passedDays);
$achievement = Achievement::getByPassedDays($event->challenge->passedDays());

if (! $achievement) {
return;
Expand Down
8 changes: 8 additions & 0 deletions app/Models/Challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public function isLikedBy($userId): bool
->exists();
}

public function passedDays(): int
{
return $this
->continued_at
->diff($this->created_at)
->d;
}

public function user()
{
return $this->belongsTo(User::class);
Expand Down

0 comments on commit 42c7255

Please sign in to comment.