gitlabhq/gitlabhq

View on GitHub
app/helpers/application_helper.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Method search_autocomplete_source has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def search_autocomplete_source
    projects = current_user.authorized_projects.map { |p| { label: "project: #{simple_sanitize(p.name_with_namespace)}", url: project_path(p) } }
    groups = current_user.authorized_groups.map { |group| { label: "group: #{simple_sanitize(group.name)}", url: group_path(group) } }

    default_nav = [
Severity: Minor
Found in app/helpers/application_helper.rb - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

        if @project && @project.repository.exists? && @project.repository.root_ref
          project_nav = [
            { label: "#{simple_sanitize(@project.name_with_namespace)} - Files",    url: project_tree_path(@project, @ref || @project.repository.root_ref) },
            { label: "#{simple_sanitize(@project.name_with_namespace)} - Commits",  url: project_commits_path(@project, @ref || @project.repository.root_ref) },
            { label: "#{simple_sanitize(@project.name_with_namespace)} - Network",  url: project_network_path(@project, @ref || @project.repository.root_ref) },
    Severity: Major
    Found in app/helpers/application_helper.rb - About 1 hr to fix

      Method gravatar_icon has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def gravatar_icon(user_email = '', size = nil)
          size = 40 if size.nil? || size <= 0
      
          if !Gitlab.config.gravatar.enabled || user_email.blank?
            'no_avatar.png'
      Severity: Minor
      Found in app/helpers/application_helper.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 show_last_push_widget? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def show_last_push_widget?(event)
          # Skip if event is not about added or modified non-master branch
          return false unless event && event.last_push_to_non_root? && !event.rm_ref?
      
          project = event.project
      Severity: Minor
      Found in app/helpers/application_helper.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