SysMO-DB/seek

View on GitHub
app/controllers/publications_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

Method associate_authors has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def associate_authors
    publication = @publication
    projects = publication.projects
    projects = current_user.person.projects if projects.empty?
    association = {}
Severity: Minor
Found in app/controllers/publications_controller.rb - About 2 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 publications_controller.rb has 268 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class PublicationsController < ApplicationController
  
  include IndexPager
  include DotGenerator
  include Seek::AssetsCommon
Severity: Minor
Found in app/controllers/publications_controller.rb - About 2 hrs to fix

    Method update has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

      def update
        valid = true
        unless params[:author].blank?
          person_ids = params[:author].values.reject {|id_string| id_string == ""}
          if person_ids.uniq.size == person_ids.size
    Severity: Minor
    Found in app/controllers/publications_controller.rb - About 2 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

    Method update has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def update
        valid = true
        unless params[:author].blank?
          person_ids = params[:author].values.reject {|id_string| id_string == ""}
          if person_ids.uniq.size == person_ids.size
    Severity: Minor
    Found in app/controllers/publications_controller.rb - About 1 hr to fix

      Method fetch_preview has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def fetch_preview
          #trim the PubMed or Doi Id
          params[:key] = params[:key].strip() unless params[:key].blank?
          params[:publication][:project_ids].reject!(&:blank?).map! { |id| id.split(',') }.flatten!
          @publication = Publication.new(params[:publication])
      Severity: Minor
      Found in app/controllers/publications_controller.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 associate_authors has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def associate_authors
          publication = @publication
          projects = publication.projects
          projects = current_user.person.projects if projects.empty?
          association = {}
      Severity: Minor
      Found in app/controllers/publications_controller.rb - About 1 hr to fix

        Method fetch_preview has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def fetch_preview
            #trim the PubMed or Doi Id
            params[:key] = params[:key].strip() unless params[:key].blank?
            params[:publication][:project_ids].reject!(&:blank?).map! { |id| id.split(',') }.flatten!
            @publication = Publication.new(params[:publication])
        Severity: Minor
        Found in app/controllers/publications_controller.rb - About 1 hr to fix

          Method create has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def create
              @publication = Publication.new(params[:publication])
              @publication.pubmed_id=nil if @publication.pubmed_id.blank?
              @publication.doi=nil if @publication.doi.blank?
              pubmed_id,doi = preprocess_doi_or_pubmed @publication.pubmed_id,@publication.doi
          Severity: Minor
          Found in app/controllers/publications_controller.rb - About 1 hr to fix

            Method create_or_update_associations has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def create_or_update_associations asset_ids, asset_type, required_action
                asset_ids.each do |id|
                  asset = asset_type.constantize.find_by_id(id)
                  if asset && asset.send("can_#{required_action}?")
                    unless Relationship.where(:subject_type => asset_type, :subject_id => asset.id, :predicate => Relationship::RELATED_TO_PUBLICATION, :other_object_type => "Publication", :other_object_id => @publication.id).first
            Severity: Minor
            Found in app/controllers/publications_controller.rb - About 55 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 create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def create
                @publication = Publication.new(params[:publication])
                @publication.pubmed_id=nil if @publication.pubmed_id.blank?
                @publication.doi=nil if @publication.doi.blank?
                pubmed_id,doi = preprocess_doi_or_pubmed @publication.pubmed_id,@publication.doi
            Severity: Minor
            Found in app/controllers/publications_controller.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 preprocess_doi_or_pubmed has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def preprocess_doi_or_pubmed pubmed_id,doi
                doi = doi.sub(%r{doi\.*:}i,"").strip unless doi.nil?
                doi.strip! unless doi.nil?
                pubmed_id.strip! unless pubmed_id.nil? || pubmed_id.is_a?(Fixnum)
                return pubmed_id,doi
            Severity: Minor
            Found in app/controllers/publications_controller.rb - About 35 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

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

                  result.authors.each_with_index do |author, index|
                    pa = PublicationAuthor.new()
                    pa.publication = @publication
                    pa.first_name = author.first_name
                    pa.last_name = author.last_name
            Severity: Minor
            Found in app/controllers/publications_controller.rb and 1 other location - About 15 mins to fix
            app/controllers/publications_controller.rb on lines 67..73

            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

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

                    result.authors.each_with_index do |author, index|
                      pa = PublicationAuthor.new()
                      pa.publication = @publication
                      pa.first_name = author.first_name
                      pa.last_name = author.last_name
            Severity: Minor
            Found in app/controllers/publications_controller.rb and 1 other location - About 15 mins to fix
            app/controllers/publications_controller.rb on lines 273..279

            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