cjmellor / level-up

Level-Up is a Laravel package introducing gamification into your applications. Users earn experience points (XP) and levels through interactions, while also unlocking achievements. It promotes engagement, competition, and fun through its dynamic leaderboard feature. Customisable to fit your specific needs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Comparison fails in recordStreak

PerryRylance opened this issue · comments

What happened?

I was testing streak continuation this morning and have found that the check at HasStreaks:51 for strict equality $diffInDays === 1.

If you see the screenshot attached you'll see that even though $diffInDays shows as 1, this evaluates to false. This is because $diffInDays is a float.

Untitled

How to reproduce the bug

Try with Laravel 11 / Carbon 3.

Package Version

1.2

PHP Version

8.2

Laravel Version

11.0

Which operating systems does with happen with?

Windows

Notes

After a quick search I found this article, breaking change in Carbon 3.0 is that these will be returned as floats now.

I cloned this repo and ran the test suite on a fresh install and can confirm that your tests are also failing on this.

Thank you for this library!

2024-06-05 09_13_23-C__Windows_System32_cmd exe

I fixed this locally by adding intval at HasStreaks:51, I tried to branch and submit a PR but looks like the repo isn't open.

@PerryRylance What do you mean the repo isn't open? You should be able to open a PR in this repo

@cjmellor Tried again just now, maybe there's something wrong with my client or account.

remote: Permission to cjmellor/level-up.git denied to PerryRylance.
fatal: unable to access 'https://github.com/cjmellor/level-up/': The requested URL returned error: 403

Yeah, weird!

If you send me the code and instructions I can look at adding it.

Please open HasStreaks and go to recordStreak. Right at the top where $diffInDays is calculated, you need to wrap the expression in intval:

$diffInDays = intval($this->getStreakLastActivity($activity)
			->activity_at
			->startOfDay()
			->diffInDays(now()->startOfDay()));

If you do a fresh install and composer install, then run the tests before making this change - you'll see your test suite fails. If you then make this change, then run the tests again, you'll see it will pass 💃