Skip to content

Past scores - #8

Merged
madebybye merged 4 commits into
mainfrom
past-scores
Jan 7, 2026
Merged

madebybye merged 4 commits into
mainfrom
past-scores

Conversation

@madebybye

Copy link
Copy Markdown
Owner

No description provided.

@madebybye
madebybye merged commit 15dbcb7 into main Jan 7, 2026
1 check passed
@claude

claude Bot commented Jan 7, 2026

Copy link
Copy Markdown

Code Review - PR #8: Past Scores

Thank you for implementing the games won tracking feature! Below is my detailed review:

Critical Issues

1. Code Duplication (Lines 142-164)

Severity: High

There is significant code duplication in ContentView.swift. Lines 142-152 and lines 154-164 are exact duplicates containing dangerColor definition and player1InDanger/player2InDanger computed properties.

Recommendation: Remove lines 154-164 entirely. This is likely a merge/paste error.

Code Quality & Best Practices

2. UserDefaults Access Pattern

Severity: Medium

The GameViewModel uses didSet property observers to persist data to UserDefaults. Issues include:

  • Every increment triggers a disk write
  • No error handling for UserDefaults failures
  • Repetitive code across multiple properties

Recommendations:

  • Consider using a dedicated persistence layer or property wrapper
  • Add error handling for UserDefaults operations
  • Consider using an enum for UserDefaults keys to prevent typos

3. Missing Documentation

Severity: Low

The new resetGamesWon() function (line 130) and games won properties lack documentation comments.

Potential Bugs

4. Games Won Increment Timing

Severity: Medium

In checkForWinner() (lines 95-100), games won is incremented immediately when a player reaches the winning score. If the user resets the game without dismissing the winner modal, the counter has already been incremented.

Scenario:

  1. Player 1 wins (counter increments to 1)
  2. Winner modal shows
  3. User long-presses to reset game instead of clicking NEW GAME
  4. Counter stays at 1, but game was never officially completed

Recommendation: Consider moving the increment to occur only when the NEW GAME button is pressed.

5. No Validation for Games Won Values

Severity: Low

The games won counter can theoretically become negative. Consider adding validation to ensure non-negative values.

UI/UX Observations

6. Accessibility

Severity: Medium

The games won text (lines 354-365) lacks accessibility labels. Consider adding .accessibilityLabel() and .accessibilityHint() modifiers to improve VoiceOver support.

Test Coverage

7. Missing Tests

Severity: Medium

No test files were found in the repository. Consider adding unit tests for:

  • GameViewModel.resetGamesWon() - verify both counters reset to 0
  • GameViewModel.checkForWinner() - verify games won increments correctly
  • UserDefaults persistence
  • Edge cases: negative values, overflow

Summary

Must Fix:

  • Remove duplicate code (lines 154-164)

Should Fix:

  • Consider games won increment timing issue
  • Add accessibility labels
  • Add unit tests

Nice to Have:

  • Add documentation comments
  • Refactor UserDefaults keys to use enum
  • Add input validation

The feature implementation is solid and follows existing code patterns well. Main concern is the code duplication which should be removed before merging. Great work on this feature!

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.

1 participant