janmayer/radiation

View on GitHub
lib/radiation/spectrum.rb

Summary

Maintainability
A
3 hrs
Test Coverage

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

        def initialize(options={})
            @peaks        = options.key?(:peaks) ? options[:peaks] : []
            @source        = options.key?(:source) ? options[:source] : nil
            @calibration= options.key?(:calibration) ? options[:calibration] : [0, 1]
            @livetime    = options.key?(:livetime) ? options[:livetime] : 1
Severity: Minor
Found in lib/radiation/spectrum.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 calibrate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def calibrate
            if @peaks.empty? or @peaks.select{|p| p.key?(:channel)}.empty?
                raise "Nothing to calibrate"
            end
Severity: Minor
Found in lib/radiation/spectrum.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 apply_linefit has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def apply_linefit(peaks)
            #calibrate using linefit
            mpeaks = peaks.delete_if{|p| p[:energy] == nil}
            x = mpeaks.collect{|p| p[:channel]}
            y = mpeaks.collect{|p| p[:energy]}
Severity: Minor
Found in lib/radiation/spectrum.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 match_channels has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def match_channels(source=@source, rounding=4)
            @peaks.each do |peak|
                source.transitions.each do |transition|
                    if channel_energy(peak[:channel]).to_f.approx_equal?(transition[:energy], rounding)
                        peak[:energy] = transition[:energy]
Severity: Minor
Found in lib/radiation/spectrum.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

There are no issues that match your filters.

Category
Status