zooniverse/Talk-Api

View on GitHub

Showing 22 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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

        def self.request(method, path, *args)
          connection.send(method, path, *args) do |req|
            req.headers['Accept'] = 'application/json'
            req.headers['Content-Type'] = 'application/json'
            yield req if block_given?
      Severity: Minor
      Found in lib/sugar.rb and 1 other location - About 40 mins to fix
      lib/markdown_api.rb on lines 15..23

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 37.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

        def self.request(method, path, *args)
          connection.send(method, path, *args) do |req|
            req.headers['Accept'] = 'text/html'
            req.headers['Content-Type'] = 'application/json'
            yield req if block_given?
      Severity: Minor
      Found in lib/markdown_api.rb and 1 other location - About 40 mins to fix
      lib/sugar.rb on lines 22..30

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 37.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            @discussions[n.section] ||= { }
            @discussions[n.section][n.subscription.source] ||= []
            @discussions[n.section][n.subscription.source] << n
      Severity: Minor
      Found in app/mailers/notification_mailer.rb and 1 other location - About 20 mins to fix
      app/mailers/notification_mailer.rb on lines 47..49

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 27.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            @started_discussions[n.section] ||= { }
            @started_discussions[n.section][n.subscription.source] ||= []
            @started_discussions[n.section][n.subscription.source] << n
      Severity: Minor
      Found in app/mailers/notification_mailer.rb and 1 other location - About 20 mins to fix
      app/mailers/notification_mailer.rb on lines 41..43

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 27.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Severity
      Category
      Status
      Source
      Language