StudyParticipant   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 30.77 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 4
loc 13
rs 10
c 2
b 0
f 1
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 studies
4
class StudyParticipant < ApplicationRecord
5
  belongs_to :participant, inverse_of: :study_participants
6
  belongs_to :study, inverse_of: :study_participants
7
  validates :participant, presence: true
8
  validates :study, presence: true
9
10
  validates_uniqueness_of :study, scope: :participant
11
  validates_uniqueness_of :participant, scope: :study
12
  
13 View Code Duplication
  def to_s
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
14
    "#{participant} #{study}"
15
  end
16
end
17
18
# == Schema Information
19
#
20
# Table name: study_participants
21
#
22
#  id             :integer          not null, primary key
23
#  participant_id :integer          not null
24
#  study_id       :integer          not null
25
#  subject_number :string        
26
#  created_at     :datetime         not null
27
#  updated_at     :datetime         not null
28
#
29
# Indexes
30
#
31
#  index_participant_study                     (participant_id,study_id) UNIQUE
32
#  index_study_participants_on_participant_id  (participant_id)
33
#  index_study_participants_on_study_id        (study_id)
34
#  index_study_subject_number                  (study_id, subject_number)
35
#
36