Noosfero/noosfero

View on GitHub
app/models/article.rb

Summary

Maintainability
F
4 days
Test Coverage

Class Article has 120 methods (exceeds 20 allowed). Consider refactoring.
Open

class Article < ApplicationRecord
  module Editor
    TEXTILE = "textile"
    TINY_MCE = "tiny_mce"
    RAW_HTML = "raw_html"
Severity: Major
Found in app/models/article.rb - About 2 days to fix

    File article.rb has 709 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Article < ApplicationRecord
      module Editor
        TEXTILE = "textile"
        TINY_MCE = "tiny_mce"
        RAW_HTML = "raw_html"
    Severity: Major
    Found in app/models/article.rb - About 1 day to fix

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

        def cache_key(params = {}, the_profile = nil, language = "en")
          active_record_cache_key + "-" + language +
            (allow_post_content?(the_profile) ? "-owner" : "") +
            (params[:npage] ? "-npage-#{params[:npage]}" : "") +
            (params[:year] ? "-year-#{params[:year]}" : "") +
      Severity: Minor
      Found in app/models/article.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 body_images_paths has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def body_images_paths
          paths = Nokogiri::HTML.fragment(self.body.to_s).css("img[src]").collect do |i|
            src = i["src"]
            src = URI.escape src if self.new_record? # xss_terminate runs on save
            (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, src).to_s : src
      Severity: Minor
      Found in app/models/article.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

      Method validate_custom_fields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate_custom_fields
            if metadata.has_key?("custom_fields")
              custom_fields = metadata["custom_fields"]
              if custom_fields.present?
                custom_fields.each do |key, field|
      Severity: Minor
      Found in app/models/article.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

      Method author_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def author_name(version_number = nil)
          person = author_by_version(version_number)
          if version_number
            person ? person.name : environment.name
          else
      Severity: Minor
      Found in app/models/article.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

      There are no issues that match your filters.

      Category
      Status