zooniverse/Talk-Api

View on GitHub

Showing 16 of 22 total issues

Class ApplicationPolicy has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

class ApplicationPolicy
  attr_reader :user, :record

  def initialize(user, record)
    @user = user
Severity: Minor
Found in app/policies/application_policy.rb - About 2 hrs to fix

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

        def parse_mentions
          self.mentioning = { }
          self.group_mentioning = { }
          body.scan(MATCH_MENTIONS).each do |focus_mention, focus_type, focus_id, group_mention, group_name, user_mention, login|
            if focus_mention
    Severity: Minor
    Found in app/models/concerns/comment/mentioning.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

    Consider simplifying this complex logical expression.
    Open

        if Array.wrap(record).compact.any? { |c| c.discussion.board.section == 'zooniverse' }
          logged_in? && !locked? && writable? && confirmed? && of_posting_age?
        else
          logged_in? && !locked? && writable? && confirmed?
        end
    Severity: Critical
    Found in app/policies/comment_policy.rb - About 1 hr to fix

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

        def update
          find_resource unless resource
          authorize unless authorized?
          update_resource
          validate unless validated?
      Severity: Minor
      Found in app/services/concerns/talk_service.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 create has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          build unless resource
          authorize unless authorized?
          validate unless validated?
          resource.save!
      Severity: Minor
      Found in app/services/concerns/talk_service.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 has_role? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def has_role?(role)
            return false unless logged_in?
            return true if roles_in('zooniverse').include?(role)
            record_sections.each do |section|
              roles = roles_in section
      Severity: Minor
      Found in app/policies/application_policy.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 set_token! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_token!
          tries = 0
          begin
            self.token = SecureRandom.hex 20
            save! unless new_record?
      Severity: Minor
      Found in app/models/unsubscribe_token.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 participant? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def participant?
            return false unless logged_in?
            Array.wrap(record).each do |r|
              return false unless r.users.exists?(id: user.id)
            end
      Severity: Minor
      Found in app/policies/application_policy.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 write_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def write_data
          ::File.open("#{ name }.json", 'w').tap do |file|
            file.write '['
            if row_count > 0
              each_row do |row, index|
      Severity: Minor
      Found in app/workers/concerns/data_export_worker.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 for_roles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def for_roles
            user_roles.collect do |section, roles|
              roles << 'translator' if translator_for?(roles)
              roles << 'team' if team_for?(section)
              roles << 'moderator' if 'admin'.in?(roles) # admin is the owner role for the section
      Severity: Minor
      Found in app/policies/board_policy.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 build has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def build
          set_user
      
          super.tap do |built|
            built.user_ip = user_ip
      Severity: Minor
      Found in app/services/message_service.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 accessible_section? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def accessible_section?(roles = ['admin'])
            return true if zooniverse_admin?
            Array.wrap(record).each do |r|
              return false unless privileged_sections(*roles).include?(r.section)
            end
      Severity: Minor
      Found in app/policies/application_policy.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 perform has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def perform(user_id, digest)
          user = ::User.find user_id
      
          return unless user.valid_email
      
      
      Severity: Minor
      Found in app/workers/notification_email_worker.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 authorize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def authorize
          build unless resource
          @authorized = policy.send "#{ action }?"
          @authorized &= actioning? && can_action? if updating?
          unauthorized! unless authorized?
      Severity: Minor
      Found in app/services/moderation_service.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 record_sections has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def record_sections
            sections = Array.wrap(record).collect do |r|
              r.section if r.respond_to?(:section)
            end.compact.uniq
            sections.empty? ? ['zooniverse'] : sections
      Severity: Minor
      Found in app/policies/application_policy.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 user_roles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def user_roles
            return @_roles if @_roles
            return { } unless logged_in?
            @_roles = { }
            sections = (record_sections + ['zooniverse']).uniq
      Severity: Minor
      Found in app/policies/application_policy.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

      Severity
      Category
      Status
      Source
      Language