amahi/platform

View on GitHub
app/models/app.rb

Summary

Maintainability
F
3 days
Test Coverage

File app.rb has 460 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'tempfile'
require 'digest/md5'
require 'amahi_api'
require 'command'
require 'downloader'
Severity: Minor
Found in app/models/app.rb - About 7 hrs to fix

    Method install_bg has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

        def install_bg
            # Change permissions of docker.sock file
            if Rails.env=="production"
                cmd = Command.new("chmod 666 /var/run/docker.sock")
                cmd.execute
    Severity: Minor
    Found in app/models/app.rb - About 5 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 install_bg has 103 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def install_bg
            # Change permissions of docker.sock file
            if Rails.env=="production"
                cmd = Command.new("chmod 666 /var/run/docker.sock")
                cmd.execute
    Severity: Major
    Found in app/models/app.rb - About 4 hrs to fix

      Class App has 32 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class App < ApplicationRecord
      
          # App and Log storage path is different for both production and development environment.
          BASE_PORT = 35000
          if Rails.env == "production"
      Severity: Minor
      Found in app/models/app.rb - About 4 hrs to fix

        Method uninstall_bg has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def uninstall_bg
                if Rails.env=="production"
                    cmd = Command.new("chmod 666 /var/run/docker.sock")
                    cmd.execute
                end
        Severity: Minor
        Found in app/models/app.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 uninstall_bg has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def uninstall_bg
                if Rails.env=="production"
                    cmd = Command.new("chmod 666 /var/run/docker.sock")
                    cmd.execute
                end
        Severity: Minor
        Found in app/models/app.rb - About 1 hr to fix

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

              def install_theme(installer, source)
          
                  return if (installer.source_url.nil? or installer.source_url.blank?)
          
                  dir = nil
          Severity: Minor
          Found in app/models/app.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 install_webapp has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def install_webapp(installer, source)
          
                  name = webapp_name(installer.url_name)
                  path = WEBAPP_PATH % name
          
          
          Severity: Minor
          Found in app/models/app.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

          Avoid too many return statements within this method.
          Open

                      return false
          Severity: Major
          Found in app/models/app.rb - About 30 mins to fix

            Method check_availability has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.check_availability
                    progress = Rails.cache.read("progress")
                    return true if progress.blank?
                    return true if progress == 999
            
            
            Severity: Minor
            Found in app/models/app.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