gitlabhq/gitlabhq

View on GitHub
app/presenters/project_presenter.rb

Summary

Maintainability
D
1 day
Test Coverage

Class ProjectPresenter has 44 methods (exceeds 20 allowed). Consider refactoring.
Open

class ProjectPresenter < Gitlab::View::Presenter::Delegated
  include ActionView::Helpers::NumberHelper
  include ActionView::Helpers::UrlHelper
  include GitlabRoutingHelper
  include StorageHelper
Severity: Minor
Found in app/presenters/project_presenter.rb - About 6 hrs to fix

    File project_presenter.rb has 340 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class ProjectPresenter < Gitlab::View::Presenter::Delegated
      include ActionView::Helpers::NumberHelper
      include ActionView::Helpers::UrlHelper
      include GitlabRoutingHelper
      include StorageHelper
    Severity: Minor
    Found in app/presenters/project_presenter.rb - About 4 hrs to fix

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

        def kubernetes_cluster_anchor_data
          if can_instantiate_cluster?
            if clusters.empty?
              AnchorData.new(false,
                             statistic_icon + _('Add Kubernetes cluster'),
      Severity: Minor
      Found in app/presenters/project_presenter.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 default_view has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def default_view
          return anonymous_project_view unless current_user
      
          user_view = current_user.project_view
      
      
      Severity: Minor
      Found in app/presenters/project_presenter.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 readme_anchor_data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def readme_anchor_data
          if current_user && can_current_user_push_to_default_branch? && repository.readme.nil?
            AnchorData.new(false,
                           statistic_icon + _('Add README'),
                           add_readme_path)
      Severity: Minor
      Found in app/presenters/project_presenter.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 autodevops_anchor_data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def autodevops_anchor_data(show_auto_devops_callout: false)
          if current_user && can?(current_user, :admin_pipeline, project) && repository.gitlab_ci_yml.blank? && !show_auto_devops_callout
            if auto_devops_enabled?
              AnchorData.new(false,
                             statistic_icon('settings') + _('Auto DevOps enabled'),
      Severity: Minor
      Found in app/presenters/project_presenter.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

        def contribution_guide_anchor_data
          if current_user && can_current_user_push_to_default_branch? && repository.contribution_guide.blank?
            AnchorData.new(false,
                           statistic_icon + _('Add CONTRIBUTING'),
                           add_contribution_guide_path)
      Severity: Minor
      Found in app/presenters/project_presenter.rb and 1 other location - About 30 mins to fix
      app/presenters/project_presenter.rb on lines 229..239

      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 32.

      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 changelog_anchor_data
          if current_user && can_current_user_push_to_default_branch? && repository.changelog.blank?
            AnchorData.new(false,
                           statistic_icon + _('Add CHANGELOG'),
                           add_changelog_path)
      Severity: Minor
      Found in app/presenters/project_presenter.rb and 1 other location - About 30 mins to fix
      app/presenters/project_presenter.rb on lines 263..273

      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 32.

      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 tags_anchor_data
          AnchorData.new(true,
                         statistic_icon('label') +
                         n_('%{strong_start}%{tag_count}%{strong_end} Tag', '%{strong_start}%{tag_count}%{strong_end} Tags', repository.tag_count).html_safe % {
                           tag_count: number_with_delimiter(repository.tag_count),
      Severity: Minor
      Found in app/presenters/project_presenter.rb and 1 other location - About 25 mins to fix
      app/presenters/project_presenter.rb on lines 184..192

      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 31.

      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 branches_anchor_data
          AnchorData.new(true,
                         statistic_icon('branch') +
                         n_('%{strong_start}%{branch_count}%{strong_end} Branch', '%{strong_start}%{branch_count}%{strong_end} Branches', repository.branch_count).html_safe % {
                           branch_count: number_with_delimiter(repository.branch_count),
      Severity: Minor
      Found in app/presenters/project_presenter.rb and 1 other location - About 25 mins to fix
      app/presenters/project_presenter.rb on lines 195..203

      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 31.

      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

      There are no issues that match your filters.

      Category
      Status