otwcode/otwarchive

View on GitHub
app/models/collection_item.rb

Summary

Maintainability
C
1 day
Test Coverage

Class CollectionItem has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class CollectionItem < ApplicationRecord
  APPROVAL_OPTIONS = [
    ["", :unreviewed],
    [ts("Approved"), :approved],
    [ts("Rejected"), :rejected]
Severity: Minor
Found in app/models/collection_item.rb - About 2 hrs to fix

    Method approve has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def approve(user)
        if user.nil?
          # this is being run via rake task eg for importing collections
          approve_by_user
          approve_by_collection
    Severity: Minor
    Found in app/models/collection_item.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 notify_of_reveal has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def notify_of_reveal
        unless self.unrevealed? || !self.posted?
          recipient_pseuds = Pseud.parse_bylines(self.recipients)[:pseuds]
          recipient_pseuds.each do |pseud|
            unless pseud.user.preference.recipient_emails_off
    Severity: Minor
    Found in app/models/collection_item.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 approve_automatically has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def approve_automatically
        return unless self.new_record?
    
        # approve with the current user, who is the person who has just
        # added this item -- might be either moderator or owner
    Severity: Minor
    Found in app/models/collection_item.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 send_work_invitation has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def send_work_invitation
        if !approved_by_user? && approved_by_collection? && self.new_record?
          if !User.current_user.is_author_of?(item)
            # a maintainer is attempting to add this work to their collection
            # so we send an email to all the works owners
    Severity: Minor
    Found in app/models/collection_item.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 update_work has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      def update_work
        return unless item.is_a?(Work) && item.persisted? && !item.saved_change_to_id?
    
        if work.present?
          work.update_anon_unrevealed
    Severity: Minor
    Found in app/models/collection_item.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 notify_of_unrevealed_or_anonymous has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      def notify_of_unrevealed_or_anonymous
        # This CollectionItem's anonymous/unrevealed status can only affect the
        # item's status if (a) the CollectionItem is approved by the user and (b)
        # the item is a work. (Bookmarks can't be anonymous/unrevealed at the
        # moment.)
    Severity: Minor
    Found in app/models/collection_item.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 notify_archivist_added has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def notify_archivist_added
        return unless User.current_user&.archivist && collection.user_is_maintainer?(User.current_user)
    
        item.users.each do |email_recipient|
          next if email_recipient.preference.collection_emails_off
    Severity: Minor
    Found in app/models/collection_item.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 item_creator_pseuds has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def item_creator_pseuds
        if self.item
          if self.item.respond_to?(:pseuds)
            self.item.pseuds
          elsif self.item.respond_to?(:pseud)
    Severity: Minor
    Found in app/models/collection_item.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 set_anonymous_and_unrevealed has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def set_anonymous_and_unrevealed
        if self.new_record? && collection
          self.unrevealed = true if collection.reload.unrevealed?
          self.anonymous = true if collection.reload.anonymous?
        end
    Severity: Minor
    Found in app/models/collection_item.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