CalebFenton/dex-oracle

View on GitHub
lib/oracle.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Assignment Branch Condition size for divine is too high. [16.19/15]
Open

  def divine
    puts "Optimizing #{@methods.size} methods over #{@smali_files.size} Smali files."
    made_changes = process_plugins
    @smali_files.each(&:update) if made_changes
    optimizations = {}
Severity: Minor
Found in lib/oracle.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method filter_methods has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def self.filter_methods(smali_files, include_types, exclude_types)
    methods = []
    smali_files.each do |smali_file|
      smali_file.methods.each do |method|
        if include_types
Severity: Minor
Found in lib/oracle.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 process_plugins has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def process_plugins
    made_changes = false
    loop do
      sweep_changes = false
      Plugin.plugins.each do |p|
Severity: Minor
Found in lib/oracle.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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def initialize(smali_dir, driver, include_types, exclude_types, disable_plugins)
Severity: Minor
Found in lib/oracle.rb - About 35 mins to fix

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

      def self.enumerate_files(dir, ext)
        # On Windows, filenames with unicode characters do not show up with Dir#glob or Dir#[]
        # They do, however, show up with Dir.entries, which is fine because it seems to be
        # the only Dir method that let's me set UTF-8 encoding. I must be missing something.
        # OH WELL. Do it the hard way.
    Severity: Minor
    Found in lib/oracle.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

    Do not use semicolons to terminate expressions.
    Open

        optimizations = optimizations.inject(Hash.new(0)) { |memo, subhash| subhash.each { |prod, value| memo[prod] += value } ; memo }
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.

    Example:

    # bad
    foo = 1; bar = 2;
    baz = 3;
    
    # good
    foo = 1
    bar = 2
    baz = 3

    Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
    Open

          next if entry == '.' or entry == '..'
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    This cop checks against comparing a variable with multiple items, where Array#include? could be used instead to avoid code repetition.

    Example:

    # bad
    a = 'a'
    foo if a == 'a' || a == 'b' || a == 'c'
    
    # good
    a = 'a'
    foo if ['a', 'b', 'c'].include?(a)

    Missing magic comment # frozen_string_literal: true.
    Open

    require_relative 'dex-oracle/logging'
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

    Example: EnforcedStyle: when_needed (default)

    # The `when_needed` style will add the frozen string literal comment
    # to files only when the `TargetRubyVersion` is set to 2.3+.
    # bad
    module Foo
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Foo
      # ...
    end

    Example: EnforcedStyle: always

    # The `always` style will always add the frozen string literal comment
    # to a file, regardless of the Ruby version or if `freeze` or `<<` are
    # called on a string literal.
    # bad
    module Bar
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Bar
      # ...
    end

    Example: EnforcedStyle: never

    # The `never` will enforce that the frozen string literal comment does
    # not exist in a file.
    # bad
    # frozen_string_literal: true
    
    module Baz
      # ...
    end
    
    # good
    module Baz
      # ...
    end

    Convert if nested inside else to elsif.
    Open

            full_path if entry.downcase.end_with?(ext)
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

    Example:

    # bad
    if condition_a
      action_a
    else
      if condition_b
        action_b
      else
        action_c
      end
    end
    
    # good
    if condition_a
      action_a
    elsif condition_b
      action_b
    else
      action_c
    end

    Pass &:optimizations as an argument to collect instead of a block.
    Open

        optimizations = Plugin.plugins.collect { |plugin| plugin.optimizations }
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    Use symbols as procs when possible.

    Example:

    # bad
    something.map { |s| s.upcase }
    
    # good
    something.map(&:upcase)

    Space found before semicolon.
    Open

        optimizations = optimizations.inject(Hash.new(0)) { |memo, subhash| subhash.each { |prod, value| memo[prod] += value } ; memo }
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    Checks for semicolon (;) preceded by space.

    Example:

    # bad
    x = 1 ; y = 2
    
    # good
    x = 1; y = 2

    Use || instead of or.
    Open

          next if entry == '.' or entry == '..'
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

    Example: EnforcedStyle: always (default)

    # bad
    foo.save and return
    
    # bad
    if foo and bar
    end
    
    # good
    foo.save && return
    
    # good
    if foo && bar
    end

    Example: EnforcedStyle: conditionals

    # bad
    if foo and bar
    end
    
    # good
    foo.save && return
    
    # good
    foo.save and return
    
    # good
    if foo && bar
    end

    Useless assignment to variable - smali_files.
    Open

        smali_files = file_paths.collect { |path| SmaliFile.new(path) }
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Use each_with_object instead of inject.
    Open

        optimizations = optimizations.inject(Hash.new(0)) { |memo, subhash| subhash.each { |prod, value| memo[prod] += value } ; memo }
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    This cop looks for inject / reduce calls where the passed in object is returned at the end and so could be replaced by eachwithobject without the need to return the object at the end.

    However, we can't replace with eachwithobject if the accumulator parameter is assigned to within the block.

    Example:

    # bad
    [1, 2].inject({}) { |a, e| a[e] = e; a }
    
    # good
    [1, 2].each_with_object({}) { |e, a| a[e] = e }

    Useless assignment to variable - optimizations.
    Open

        optimizations = {}
    Severity: Minor
    Found in lib/oracle.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    There are no issues that match your filters.

    Category
    Status