zammad/zammad

View on GitHub
app/models/ticket/article.rb

Summary

Maintainability
D
1 day
Test Coverage

Method check_mentions has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  def check_mentions
    begin
      mention_user_ids = Nokogiri::HTML(body).css('a[data-mention-user-id]').pluck('data-mention-user-id')
    rescue => e
      Rails.logger.error "Can't parse body '#{body}' as HTML for extracting Mentions."
Severity: Minor
Found in app/models/ticket/article.rb - About 3 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 article.rb has 299 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Ticket::Article < ApplicationModel
  include HasDefaultModelUserRelations

  include CanBeImported
  include HasActivityStreamLog
Severity: Minor
Found in app/models/ticket/article.rb - About 3 hrs to fix

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

    class Ticket::Article < ApplicationModel
      include HasDefaultModelUserRelations
    
      include CanBeImported
      include HasActivityStreamLog
    Severity: Minor
    Found in app/models/ticket/article.rb - About 2 hrs to fix

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

        def self.insert_urls(article)
          return article if article['attachments'].blank?
          return article if !article['content_type'].match?(%r{text/html}i)
          return article if article['body'] !~ %r{<img}i
      
      
      Severity: Minor
      Found in app/models/ticket/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 attachments_inline has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def attachments_inline
          inline_attachments = {}
          body.gsub(%r{<img[[:space:]](|.+?)src="cid:(.+?)"(|.+?)>}im) do |_item|
            cid = $2
      
      
      Severity: Minor
      Found in app/models/ticket/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 check_mentions has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def check_mentions
          begin
            mention_user_ids = Nokogiri::HTML(body).css('a[data-mention-user-id]').pluck('data-mention-user-id')
          rescue => e
            Rails.logger.error "Can't parse body '#{body}' as HTML for extracting Mentions."
      Severity: Minor
      Found in app/models/ticket/article.rb - About 1 hr to fix

        Avoid too many return statements within this method.
        Open

              return if !check_mentions_raises_error
        Severity: Major
        Found in app/models/ticket/article.rb - About 30 mins to fix

          There are no issues that match your filters.

          Category
          Status