0
我使用Code Climate同步我的應用程序以進行代碼審查。RAILS中的重構方法複雜性
LIB /模型/用戶/同步/ basecamp_inc.rb
def todo_list(todos,basecamp_account,proj_id)
todos.map{|todo|
task = basecamp_tasklist(proj_id,todo['id'],basecamp_account)
task_list(task['todos']['remaining'],task['name'],'remain') if task['todos']['remaining'].present?
task_list(task['todos']['completed'],task['name'],'complete') if task['todos']['completed'].present?
}
end
def task_list(tasks,todo_list,status)
tasks.map{|task|
task_created(task,todo_list)
task['assignee'].present? && user_owner?(task['assignee']['name']) ? save_task_activity('was assigned to a',task,todo_list,task['updated_at'],'assign') : [tasks,todo_list,status]
status == 'complete' && user_owner?(task['completer']['name']) && current_date?(task['completed_at']) ? save_task_activity('finished',task,todo_list,task['completed_at'],'finished') : [tasks,todo_list,status]
}
end
上述被編碼氣候檢測爲具有複雜的方法的代碼。我不明白爲什麼Code Climate認爲它很複雜。那麼,那個代碼的等級仍然是C,我想重構它。我該如何改進?
謝謝你會試試你的建議 – xirukitepe