zammad/zammad

View on GitHub
app/models/package.rb

Summary

Maintainability
D
2 days
Test Coverage

File package.rb has 367 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Package < ApplicationModel
  @@root = Rails.root.to_s # rubocop:disable Style/ClassVars

=begin

Severity: Minor
Found in app/models/package.rb - About 4 hrs to fix

    Method install has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.install(data)
        if data[:file]
          json    = _read_file(data[:file], true)
          package = JSON.parse(json)
        elsif data[:string]
    Severity: Major
    Found in app/models/package.rb - About 2 hrs to fix

      Method install has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.install(data)
          if data[:file]
            json    = _read_file(data[:file], true)
            package = JSON.parse(json)
          elsif data[:string]
      Severity: Minor
      Found in app/models/package.rb - About 2 hrs 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 link has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.link(package_base_dir)
      
          # link files
          Dir.glob("#{package_base_dir}/**/*") do |entry|
            entry = entry.sub('//', '/')
      Severity: Minor
      Found in app/models/package.rb - About 2 hrs 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 link has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.link(package_base_dir)
      
          # link files
          Dir.glob("#{package_base_dir}/**/*") do |entry|
            entry = entry.sub('//', '/')
      Severity: Minor
      Found in app/models/package.rb - About 1 hr to fix

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

          def self._write_file(file, permission, data)
            location = "#{@@root}/#{file}"
        
            # rename existing file if not already the same file
            if File.exist?(location)
        Severity: Minor
        Found in app/models/package.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 _write_file has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self._write_file(file, permission, data)
            location = "#{@@root}/#{file}"
        
            # rename existing file if not already the same file
            if File.exist?(location)
        Severity: Minor
        Found in app/models/package.rb - About 1 hr to fix

          Method uninstall has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.uninstall(data)
          
              if data[:string]
                package = JSON.parse(data[:string])
              else
          Severity: Minor
          Found in app/models/package.rb - About 1 hr to fix

            Method verify has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def verify
            
                # get package
                json_file = self.class._get_bin(name, version)
                package   = JSON.parse(json_file)
            Severity: Minor
            Found in app/models/package.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 uninstall has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.uninstall(data)
            
                if data[:string]
                  package = JSON.parse(data[:string])
                else
            Severity: Minor
            Found in app/models/package.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 ensure_no_duplicate_files! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.ensure_no_duplicate_files!(name, location)
                all_files.each do |check_package, check_files|
                  next if check_package == name
                  next if check_files.exclude?(location)
            
            
            Severity: Minor
            Found in app/models/package.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