在 Rails 项目上运行 reek 时收到警告:
[36]:ArborReloaded::UserStoryService#destroy_stories 有大约 8 个语句 (TooManyStatements)
这是方法:
def destroy_stories(project_id, user_stories)
errors = []
@project = Project.find(project_id)
user_stories.each do |current_user_story_id|
unless @project.user_stories.find(current_user_story_id).destroy
errors.push("Error destroying user_story: #{current_user_story_id}")
end
end
if errors.compact.length == 0
@common_response.success = true
else
@common_response.success = false
@common_response.errors = errors
end
@common_response
end
如何最小化这种方法?