NUBIC/surveyor

View on GitHub
lib/surveyor/redcap_parser.rb

Summary

Maintainability
D
2 days
Test Coverage

Method build_and_set has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  def build_and_set(context, r)
    # text_validation_type text_validation_min text_validation_max
    min = r[:text_validation_min].to_s.blank? ? nil : r[:text_validation_min].to_s
    max = r[:text_validation_max].to_s.blank? ? nil : r[:text_validation_max].to_s
    type = r[:text_validation_type].to_s.blank? ? nil : r[:text_validation_type].to_s
Severity: Minor
Found in lib/surveyor/redcap_parser.rb - About 5 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File redcap_parser.rb has 252 lines of code (exceeds 250 allowed). Consider refactoring.
Open

%w(survey survey_section question_group question dependency dependency_condition answer validation validation_condition).each {|model| require model }
require 'active_support' # for humanize
module Surveyor
  class RedcapParserError < StandardError; end
  class RedcapParser
Severity: Minor
Found in lib/surveyor/redcap_parser.rb - About 2 hrs to fix

    Method build_and_set has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      def build_and_set(context, r)
        case r[:field_type]
        when "text"
          self.attributes = {
            :response_class => "string",
    Severity: Minor
    Found in lib/surveyor/redcap_parser.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method build_and_set has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def build_and_set(context, r)
        # text_validation_type text_validation_min text_validation_max
        min = r[:text_validation_min].to_s.blank? ? nil : r[:text_validation_min].to_s
        max = r[:text_validation_max].to_s.blank? ? nil : r[:text_validation_max].to_s
        type = r[:text_validation_type].to_s.blank? ? nil : r[:text_validation_type].to_s
    Severity: Minor
    Found in lib/surveyor/redcap_parser.rb - About 1 hr to fix

      Method build_and_set has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def build_and_set(context, r)
          case r[:field_type]
          when "text"
            self.attributes = {
              :response_class => "string",
      Severity: Minor
      Found in lib/surveyor/redcap_parser.rb - About 1 hr to fix

        Method parse has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def parse(str, filename)
              csvlib = Surveyor::Common.csv_impl
              begin
                csvlib.parse(str, :headers => :first_row, :return_headers => true, :header_converters => :symbol) do |r|
                  if r.header_row? # header row
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method decompose_rule has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def decompose_rule(str)
            # see spec/lib/redcap_parser_spec.rb for examples
            letters = ('A'..'Z').to_a
            rule = str
            components = str.split(/\band\b|\bor\b|\((?!\d)|\)(?!\(|\])/).reject(&:blank?).map(&:strip)
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method missing_columns has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def missing_columns(r)
              missing = []
              missing << "choices_or_calculations" unless r.map(&:to_s).include?("choices_or_calculations") or r.map(&:to_s).include?("choices_calculations_or_slider_labels")
              missing << "text_validation_type" unless r.map(&:to_s).include?("text_validation_type") or r.map(&:to_s).include?("text_validation_type_or_show_slider_number")
              missing += (static_required_columns - r.map(&:to_s))
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb - About 25 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method build_and_set has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def build_and_set(context, r)
            if !r[:section_header].blank?
              context[:survey_section].questions.build({:display_type => "label", :text => r[:section_header], :display_order => context[:survey_section].questions.size})
              Surveyor::RedcapParser.rake_trace "label_ "
            end
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb - About 25 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

              when "integer"
                context[:question].display_type = :integer if context[:question].display_type == :string
                context[:question].answers.each do |a|
                  self.rule = "A"
                  a.validations << context[:validation] = self
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb and 1 other location - About 55 mins to fix
        lib/surveyor/redcap_parser.rb on lines 272..277

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 45.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

              when "number"
                context[:question].display_type = :float if context[:question].display_type == :string
                context[:question].answers.each do |a|
                  self.rule = "A"
                  a.validations << context[:validation] = self
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb and 1 other location - About 55 mins to fix
        lib/surveyor/redcap_parser.rb on lines 265..270

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 45.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

              when "email"
                context[:question].answers.each do |a|
                  self.rule = "A"
                  a.validations << context[:validation] = self
                  context[:validation].validation_conditions.build(:rule_key => "A", :operator => "=~", :regexp => "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$")
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb and 1 other location - About 30 mins to fix
        lib/surveyor/redcap_parser.rb on lines 279..283

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 33.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

              when "phone"
                context[:question].answers.each do |a|
                            self.rule = "A"
                  a.validations << context[:validation] = self
                  context[:validation].validation_conditions.build(:rule_key => "A", :operator => "=~", :regexp => "\d{3}.*\d{4}")
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb and 1 other location - About 30 mins to fix
        lib/surveyor/redcap_parser.rb on lines 259..263

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 33.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            when "notes"
              self.attributes = {
                :response_class => "text",
                :text => "Notes",
                :display_order => context[:question].answers.size }
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb and 1 other location - About 15 mins to fix
        lib/surveyor/redcap_parser.rb on lines 203..208

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 25.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            when "text"
              self.attributes = {
                :response_class => "string",
                :text => "Text",
                :display_order => context[:question].answers.size }
        Severity: Minor
        Found in lib/surveyor/redcap_parser.rb and 1 other location - About 15 mins to fix
        lib/surveyor/redcap_parser.rb on lines 209..214

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 25.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status