SurveyParticipant   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 35.71 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 5
loc 14
rs 10
c 2
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A to_s() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# frozen_string_literal: true
2
3
# Association class between participants and surveys
4
class SurveyParticipant < ApplicationRecord
5
  belongs_to :participant, inverse_of: :survey_participants
6
  belongs_to :survey, inverse_of: :survey_participants
7
8
  validates :participant, presence: true
9
  validates :survey, presence: true
10
11
  validates_uniqueness_of :survey, scope: :participant
12
  validates_uniqueness_of :participant, scope: :survey
13 View Code Duplication
  
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
14
  def to_s
15
    "#{participant} #{survey}"
16
  end
17
end
18
19
# == Schema Information
20
#
21
# Table name: survey_participants
22
#
23
#  id             :integer          not null, primary key
24
#  participant_id :integer          not null
25
#  survey_id      :integer          not null
26
#  created_at     :datetime         not null
27
#  updated_at     :datetime         not null
28
#
29
# Indexes
30
#
31
#  index_by_participant_survey                  (participant_id,survey_id) UNIQUE
32
#  index_survey_participants_on_participant_id  (participant_id)
33
#  index_survey_participants_on_survey_id       (survey_id)
34
#
35