gitlabhq/gitlabhq

View on GitHub
lib/gitlab/diff/file.rb

Summary

Maintainability
D
2 days
Test Coverage

Class File has 69 methods (exceeds 20 allowed). Consider refactoring.
Open

    class File
      include Gitlab::Utils::StrongMemoize

      attr_reader :diff, :repository, :diff_refs, :fallback_diff_refs, :unique_identifier

Severity: Major
Found in lib/gitlab/diff/file.rb - About 1 day to fix

    File file.rb has 321 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Gitlab
      module Diff
        class File
          include Gitlab::Utils::StrongMemoize
    
    
    Severity: Minor
    Found in lib/gitlab/diff/file.rb - About 3 hrs to fix

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

            def simple_viewer_class
              return DiffViewer::Collapsed if collapsed?
              return DiffViewer::NotDiffable unless diffable?
              return DiffViewer::Text if modified_file? && text?
              return DiffViewer::NoPreview if content_changed?
      Severity: Minor
      Found in lib/gitlab/diff/file.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 diff_lines_for_serializer has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def diff_lines_for_serializer
              strong_memoize(:diff_lines_for_serializer) do
                lines = highlighted_diff_lines
      
                next if lines.empty?
      Severity: Minor
      Found in lib/gitlab/diff/file.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

      Avoid too many return statements within this method.
      Open

              return DiffViewer::Deleted if deleted_file?
      Severity: Major
      Found in lib/gitlab/diff/file.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return DiffViewer::Added if new_file?
        Severity: Major
        Found in lib/gitlab/diff/file.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return DiffViewer::Renamed if renamed_file?
          Severity: Major
          Found in lib/gitlab/diff/file.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return DiffViewer::ModeChanged if mode_changed?
            Severity: Major
            Found in lib/gitlab/diff/file.rb - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status