crowbar/crowbar-core

View on GitHub
chef/cookbooks/barclamp/libraries/nic.rb

Summary

Maintainability
F
4 days
Test Coverage

File nic.rb has 723 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ::Nic
  include Comparable
  private
  @@interfaces = Hash.new
  @nic = nil
Severity: Major
Found in chef/cookbooks/barclamp/libraries/nic.rb - About 1 day to fix

Class Nic has 66 methods (exceeds 20 allowed). Consider refactoring.
Open

class ::Nic
  include Comparable
  private
  @@interfaces = Hash.new
  @nic = nil
Severity: Major
Found in chef/cookbooks/barclamp/libraries/nic.rb - About 1 day to fix

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

    def self.create(parent,vlan)
      nic = "#{parent}.#{vlan}"
      Chef::Log.info("Creating new VLAN interface #{nic}")
      if self.exists?(nic)
        raise ::ArgumentError.new("#{nic} already exists.")
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.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 new has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.new(nic)
    logstr=""
    if nic.is_a?(::Nic)
      return nic
    elsif o = @@interfaces[nic]
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb - About 1 hr to fix

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

    def self.create(parent,vlan)
      nic = "#{parent}.#{vlan}"
      Chef::Log.info("Creating new VLAN interface #{nic}")
      if self.exists?(nic)
        raise ::ArgumentError.new("#{nic} already exists.")
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb - About 1 hr to fix

Method refresh has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def refresh
    @addresses = ::Array.new
    @dependents = nil
    ::IO.popen("ip -o addr show dev #{@nic}") do |f|
      f.each do |line|
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.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

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

  def self.new(nic)
    logstr=""
    if nic.is_a?(::Nic)
      return nic
    elsif o = @@interfaces[nic]
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.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 find has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def self.find(nics)
      t = Hash.new
      nics.each do |n|
        n = Nic.coerce(n)
        t[n.name]=n
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.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 __nics has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def self.__nics
    res = []
    ::Dir.entries("/sys/class/net").each do |d|
      next if d == "." or d == ".."
      next unless ::File.directory?("/sys/class/net/#{d}")
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.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 create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def self.create(nic, slaves = [])
      Chef::Log.info("Creating new bridge #{nic}")
      if self.exists?(nic)
        raise ::ArgumentError.new("#{nic} already exists.")
      end
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.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 add_slave(slave)
      unless ::Nic.exists?(slave)
        raise ::ArgumentError.new("#{slave} does not exist, cannot add to bridge#{@nic}")
      end
      slave = self.class.coerce(slave)
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb and 1 other location - About 55 mins to fix
chef/cookbooks/barclamp/libraries/nic.rb on lines 791..803

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

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 add_slave(slave)
      unless ::Nic.exists?(slave)
        raise ::ArgumentError.new("#{slave} does not exist, cannot add to bridge#{@nic}")
      end
      slave = self.class.coerce(slave)
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb and 1 other location - About 55 mins to fix
chef/cookbooks/barclamp/libraries/nic.rb on lines 683..695

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

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 remove_slave(slave)
      slave = self.class.coerce(slave)
      unless self.slaves.member?(slave)
        raise ::ArgumentError.new("#{slave} is not a member of bridge #{@nic}")
      end
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb and 1 other location - About 30 mins to fix
chef/cookbooks/barclamp/libraries/nic.rb on lines 698..705

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 remove_slave(slave)
      slave = self.class.coerce(slave)
      unless self.slaves.member?(slave)
        raise ::ArgumentError.new("#{slave} is not a member of bridge #{@nic}")
      end
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb and 1 other location - About 30 mins to fix
chef/cookbooks/barclamp/libraries/nic.rb on lines 806..813

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

      5.times do
        if self.exists?(nic) && self.ovs_bridge?(nic)
          iface = ::Nic.new(nic)
          slaves.each do |slave|
            iface.add_slave slave
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb and 1 other location - About 25 mins to fix
chef/cookbooks/barclamp/libraries/nic.rb on lines 763..772

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

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

      5.times do
        if self.exists?(nic) && self.bridge?(nic)
          iface = ::Nic.new(nic)
          slaves.each do |slave|
            iface.add_slave slave
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb and 1 other location - About 25 mins to fix
chef/cookbooks/barclamp/libraries/nic.rb on lines 858..867

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

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 plug(slave)
      slave = self.class.coerce(slave)
      if slaves.member?(slave)
        raise ::ArgumentError, "#{slave} is already a member of bridge #{@nic}"
      end
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb and 1 other location - About 20 mins to fix
chef/cookbooks/barclamp/libraries/nic.rb on lines 830..835

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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    def unplug(slave)
      slave = self.class.coerce(slave)
      unless slaves.member?(slave)
        raise ::ArgumentError, "#{slave} is not a member of bridge #{@nic}"
      end
Severity: Minor
Found in chef/cookbooks/barclamp/libraries/nic.rb and 1 other location - About 20 mins to fix
chef/cookbooks/barclamp/libraries/nic.rb on lines 838..843

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