Skip to content

fix: cast cache result to int in getStarsCount#81

Merged
ManukMinasyan merged 1 commit intomainfrom
fix/github-stars-return-type
Jan 20, 2026
Merged

fix: cast cache result to int in getStarsCount#81
ManukMinasyan merged 1 commit intomainfrom
fix/github-stars-return-type

Conversation

@ManukMinasyan
Copy link
Copy Markdown
Contributor

Cache::remember returns mixed, causing type error when cached value is stored as string

Cache::remember returns mixed, causing type error when cached
value is stored as string
Copilot AI review requested due to automatic review settings January 20, 2026 01:17
@ManukMinasyan ManukMinasyan merged commit 85053c3 into main Jan 20, 2026
12 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of Cache::remember() in getStarsCount() 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 {
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants