fix: cast cache result to int in getStarsCount#81
Conversation
Cache::remember returns mixed, causing type error when cached value is stored as string
There was a problem hiding this comment.
Pull request overview
This PR fixes a type safety issue in the GitHubService::getStarsCount() method where Cache::remember() can return cached values as strings depending on the cache driver, causing type errors in strict mode. The fix adds an explicit cast to ensure the method always returns an integer as declared.
Changes:
- Added explicit
(int)cast to the return value ofCache::remember()ingetStarsCount()method
| $cacheKey = "github_stars_{$owner}_{$repo}"; | ||
|
|
||
| return Cache::remember($cacheKey, now()->addMinutes($cacheMinutes), function () use ($owner, $repo): int { | ||
| return (int) Cache::remember($cacheKey, now()->addMinutes($cacheMinutes), function () use ($owner, $repo): int { |
There was a problem hiding this comment.
While the fix correctly addresses the type safety issue with cached values, there's no test coverage for the specific scenario this PR fixes. Consider adding a test that explicitly sets a string value in the cache and verifies it's returned as an integer. This would validate that the cast works correctly when the cache returns a string representation of the number.
Cache::remember returns mixed, causing type error when cached value is stored as string