hammackj/risu

View on GitHub
lib/risu/models/host.rb

Summary

Maintainability
F
4 days
Test Coverage

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

        class Host < ActiveRecord::Base
            belongs_to :report
            has_many :items
            has_many :patches
            has_many :host_properties
Severity: Major
Found in lib/risu/models/host.rb - About 1 day to fix

    File host.rb has 478 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Risu
        module Models
    
            # Host Model
            class Host < ActiveRecord::Base
    Severity: Minor
    Found in lib/risu/models/host.rb - About 7 hrs to fix

      Method other_os_graph has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

                      def other_os_graph
                          g = Gruff::Pie.new(GRAPH_WIDTH)
                          g.title = "Other Operating Systems Percentage"
                          g.sort = false
                          g.marker_count = 1
      Severity: Minor
      Found in lib/risu/models/host.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

      Consider simplifying this complex logical expression.
      Open

                          if nt == 0 && w2k == 0 && xp == 0 && w2k3 == 0 && vista == 0 && w2k8 == 0 && w2k12 == 0 && w7 == 0 && w8 == 0 && other == 0
                              return false
                          else
                              return true
                          end
      Severity: Critical
      Found in lib/risu/models/host.rb - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

                            if linux == 0 &&
                                osx == 0 &&
                                freebsd == 0 &&
                                netbsd == 0 &&
                                cisco == 0 &&
        Severity: Critical
        Found in lib/risu/models/host.rb - About 1 hr to fix

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

                          def windows_os_graph_text
                              nt = Host.os_windows_nt.to_a.size
                              w2k = Host.os_windows_2k.to_a.size
                              xp = Host.os_windows_xp.to_a.size
                              w2k3 = Host.os_windows_2k3.to_a.size
          Severity: Minor
          Found in lib/risu/models/host.rb - About 1 hr to fix

            Method windows_os_graph_text has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                            def windows_os_graph_text
                                nt = Host.os_windows_nt.to_a.size
                                w2k = Host.os_windows_2k.to_a.size
                                xp = Host.os_windows_xp.to_a.size
                                w2k3 = Host.os_windows_2k3.to_a.size
            Severity: Minor
            Found in lib/risu/models/host.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 windows_os_graph has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                            def windows_os_graph
                                g = Gruff::Pie.new(GRAPH_WIDTH)
                                g.title = "Windows Operating Systems By Percentage"
                                g.sort = false
                                g.marker_count = 1
            Severity: Minor
            Found in lib/risu/models/host.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 windows_os_graph has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                            def windows_os_graph
                                g = Gruff::Pie.new(GRAPH_WIDTH)
                                g.title = "Windows Operating Systems By Percentage"
                                g.sort = false
                                g.marker_count = 1
            Severity: Minor
            Found in lib/risu/models/host.rb - About 1 hr to fix

              Method unsupported_os_windows has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                              def unsupported_os_windows
                                  win_95_text = ""
                                  win_98_text = ""
                                  win_me_text = ""
                                  win_nt_text = ""
              Severity: Minor
              Found in lib/risu/models/host.rb - About 1 hr to fix

                Method other_os_graph has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                                def other_os_graph
                                    g = Gruff::Pie.new(GRAPH_WIDTH)
                                    g.title = "Other Operating Systems Percentage"
                                    g.sort = false
                                    g.marker_count = 1
                Severity: Minor
                Found in lib/risu/models/host.rb - About 1 hr to fix

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

                                  def unsupported_os_windows
                                      win_95_text = ""
                                      win_98_text = ""
                                      win_me_text = ""
                                      win_nt_text = ""
                  Severity: Minor
                  Found in lib/risu/models/host.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 other_os_graph_text has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                                  def other_os_graph_text
                                      text = "This graph shows the percentage of the different Non-Windows based operating systems " +
                                      "found on the #{Report.title} network.\n\n"
                  
                                      linux = Host.os_linux.to_a.size
                  Severity: Minor
                  Found in lib/risu/models/host.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 windows_os_graph_has_data?
                                      nt = Host.os_windows_nt.to_a.size
                                      w2k = Host.os_windows_2k.to_a.size
                                      xp = Host.os_windows_xp.to_a.size
                                      w2k3 = Host.os_windows_2k3.to_a.size
                  Severity: Major
                  Found in lib/risu/models/host.rb and 1 other location - About 2 hrs to fix
                  lib/risu/graphs/windows_os_graph.rb on lines 109..125

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

                  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

                                          ip = Host.find_by_id(item.host_id).name
                                          count = Item.where(:host_id => item.host_id).where(:severity => 4).size
                  
                                          if count > 0
                                              g.data(ip, count)
                  Severity: Minor
                  Found in lib/risu/models/host.rb and 1 other location - About 20 mins to fix
                  lib/risu/graphs/top_vuln_graph.rb on lines 39..43

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

                  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