Skip to content

Commit 95a39ce

Browse files
committed
Fix: solve metadata unused variable and long lines
1 parent 7d72c57 commit 95a39ce

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

app/services/players/roster_management_service.rb

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def remove_from_roster(reason:)
6262
# @param salary [Decimal] Player salary (optional)
6363
# @param jersey_number [Integer] Jersey number (optional)
6464
# @return [Hash] Result with success status and player
65-
def self.hire_from_scouting(scouting_target:, organization:, contract_start:, contract_end:, salary: nil, jersey_number: nil, current_user: nil)
65+
def self.hire_from_scouting(scouting_target:, organization:, contract_start:, contract_end:,
66+
salary: nil, jersey_number: nil, current_user: nil)
6667
ActiveRecord::Base.transaction do
6768
# Check if this is a free agent or needs to be restored
6869
player = find_or_restore_player(scouting_target, organization)
@@ -148,7 +149,6 @@ def sync_player_matches_comprehensive(sync_service, count)
148149
begin
149150
match_details = sync_service.send(:fetch_match_details, match_id)
150151
info = match_details['info']
151-
metadata = match_details['metadata']
152152

153153
# Find player's participant data
154154
participant = info['participants'].find { |p| p['puuid'] == player.riot_puuid }
@@ -161,9 +161,8 @@ def sync_player_matches_comprehensive(sync_service, count)
161161
# Match exists - just add player stats
162162
sync_service.send(:create_player_stats, existing_match, player, participant)
163163
imported += 1
164-
else
165-
# Import full match
166-
imported += 1 if sync_service.send(:import_match, match_details, player)
164+
elsif sync_service.send(:import_match, match_details, player)
165+
imported += 1
167166
end
168167
rescue StandardError => e
169168
Rails.logger.error("Failed to import match #{match_id}: #{e.message}")
@@ -308,7 +307,11 @@ def calculate_recent_performance(player, limit: 50)
308307
total_kills = recent_stats.sum(:kills)
309308
total_deaths = recent_stats.sum(:deaths)
310309
total_assists = recent_stats.sum(:assists)
311-
avg_kda = total_deaths.zero? ? total_kills + total_assists : ((total_kills + total_assists).to_f / total_deaths).round(2)
310+
avg_kda = if total_deaths.zero?
311+
total_kills + total_assists
312+
else
313+
((total_kills + total_assists).to_f / total_deaths).round(2)
314+
end
312315

313316
# Calculate averages only for non-null values
314317
damage_shares = recent_stats.pluck(:damage_share).compact
@@ -324,7 +327,7 @@ def calculate_recent_performance(player, limit: 50)
324327
avg_vision_score: recent_stats.average(:vision_score)&.to_f&.round(1) || 0.0,
325328
avg_damage_share: damage_shares.any? ? (damage_shares.sum / damage_shares.size).round(1) : 0.0,
326329
avg_kill_participation: kill_participations.any? ? (kill_participations.sum / kill_participations.size).round(1) : 0.0,
327-
last_game_date: recent_stats.first&.match&.game_start&.to_date
330+
last_game_date: last_game_date_for(recent_stats)
328331
}
329332
end
330333

@@ -365,6 +368,17 @@ def calculate_win_rate(stats)
365368
(wins.to_f / stats.count * 100).round(1)
366369
end
367370

371+
# Helper to extract last game date without deep safe navigation chain
372+
def last_game_date_for(stats)
373+
first_stat = stats.first
374+
return nil unless first_stat
375+
376+
match = first_stat.match
377+
return nil unless match
378+
379+
match.game_start&.to_date
380+
end
381+
368382
# Extract playstyle from player notes
369383
def extract_playstyle_from_notes(notes)
370384
return nil if notes.blank?

0 commit comments

Comments
 (0)