| Total Complexity | 1 |
| Total Lines | 14 |
| Duplicated Lines | 35.71 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 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 | ||
|
|
|||
| 14 | def to_s |
||
| 15 | "#{participant} #{survey}" |
||
| 16 | end |
||
| 17 | end |
||
| 18 | |||
| 35 |