redmine/redmine

View on GitHub
app/models/wiki_page.rb

Summary

Maintainability
C
1 day
Test Coverage

Class WikiPage has 28 methods (exceeds 20 allowed). Consider refactoring.
Open

class WikiPage < ApplicationRecord
  include Redmine::SafeAttributes

  belongs_to :wiki
  has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id',
Severity: Minor
Found in app/models/wiki_page.rb - About 3 hrs to fix

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

      def handle_rename_or_move
        if !new_record? && (title_changed? || wiki_id_changed?)
          # Update redirects that point to the old title
          WikiRedirect.where(:redirects_to => title_was, :redirects_to_wiki_id => wiki_id_was).each do |r|
            r.redirects_to = title
    Severity: Minor
    Found in app/models/wiki_page.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 diff has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

      def diff(version_to=nil, version_from=nil)
        version_to = version_to ? version_to.to_i : self.content.version
        content_to = content.versions.find_by_version(version_to)
        content_from = version_from ? content.versions.find_by_version(version_from.to_i) : content_to.try(:previous)
        return nil unless content_to && content_from
    Severity: Minor
    Found in app/models/wiki_page.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 save_with_content has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def save_with_content(content)
        ret = nil
        transaction do
          ret = save
          if content.text_changed?
    Severity: Minor
    Found in app/models/wiki_page.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 safe_attributes= has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      def safe_attributes=(attrs, user=User.current)
        if attrs.respond_to?(:to_unsafe_hash)
          attrs = attrs.to_unsafe_hash
        end
        return unless attrs.is_a?(Hash)
    Severity: Minor
    Found in app/models/wiki_page.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_parent_title has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def validate_parent_title
        errors.add(:parent_title, :invalid) if @parent_title.present? && parent.nil?
        errors.add(:parent_title, :circular_dependency) if parent && (parent == self || parent.ancestors.include?(self))
        if parent_id_changed? && parent && (parent.wiki_id != wiki_id)
          errors.add(:parent_title, :not_same_project)
    Severity: Minor
    Found in app/models/wiki_page.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 handle_children_move has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def handle_children_move
        if !new_record? && saved_change_to_wiki_id?
          children.each do |child|
            child.wiki_id = wiki_id
            child.redirect_existing_links = redirect_existing_links
    Severity: Minor
    Found in app/models/wiki_page.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

    There are no issues that match your filters.

    Category
    Status