File repository.rb
has 589 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'grit/git-ruby/internal/raw_object'
require 'grit/git-ruby/internal/pack'
require 'grit/git-ruby/internal/loose'
require 'grit/git-ruby/git_object'
Method diff
has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring. Open
def diff(commit1, commit2, options = {})
patch = ''
commit_obj1 = get_object_by_sha1(commit1)
tree1 = commit_obj1.tree
- Read upRead up
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 walk_log
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
def walk_log(sha, opts, total_size = 0)
return [] if @already_searched[sha] # to prevent rechecking branches
@already_searched[sha] = true
array = []
- Read upRead up
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 ls_tree_path
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
def ls_tree_path(sha, path, append = nil)
tree = get_raw_tree(sha)
if path =~ /\//
paths = path.split('/')
last = path[path.size - 1, 1]
- Read upRead up
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
Class Repository
has 42 methods (exceeds 20 allowed). Consider refactoring. Open
class Repository
class NoSuchShaFound < StandardError
end
Method quick_diff
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
def quick_diff(tree1, tree2, path = '.', recurse = true)
# handle empty trees
return changed if tree1 == tree2
t1 = list_tree(tree1) if tree1
- Read upRead up
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 diff
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def diff(commit1, commit2, options = {})
patch = ''
commit_obj1 = get_object_by_sha1(commit1)
tree1 = commit_obj1.tree
Method ls_tree_path
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
def ls_tree_path(sha, path, append = nil)
tree = get_raw_tree(sha)
if path =~ /\//
paths = path.split('/')
last = path[path.size - 1, 1]
Method walk_log
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
def walk_log(sha, opts, total_size = 0)
return [] if @already_searched[sha] # to prevent rechecking branches
@already_searched[sha] = true
array = []
Method quick_what_changed
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def quick_what_changed(t1, t2, path, type)
changed = []
t1[type].each do |file, hsh|
t2_file = t2[type][file] rescue nil
- Read upRead up
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 look_for_commits
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def look_for_commits(commit_sha, path, looking_for, options = {})
return [] if @already_searched[commit_sha] # to prevent rechecking branches
@already_searched[commit_sha] = true
- Read upRead up
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 quick_diff
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def quick_diff(tree1, tree2, path = '.', recurse = true)
# handle empty trees
return changed if tree1 == tree2
t1 = list_tree(tree1) if tree1
Method get_subtree
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def get_subtree(commit_sha, path)
tree_sha = get_object_by_sha1(commit_sha).tree
if path && !(path == '' || path == '.' || path == './')
paths = path.split('/')
- Read upRead up
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 look_for_commits
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def look_for_commits(commit_sha, path, looking_for, options = {})
return [] if @already_searched[commit_sha] # to prevent rechecking branches
@already_searched[commit_sha] = true
Method init
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.init(dir, bare = true)
FileUtils.mkdir_p(dir) if !File.exists?(dir)
FileUtils.cd(dir) do
Method get_raw_trees
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def get_raw_trees(sha, path = '')
out = ''
cat_file(sha).split("\n").each do |line|
mode, type, sha, name = line.split(/\s/)
- Read upRead up
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 get_raw_object_by_sha1
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_raw_object_by_sha1(sha1o)
raise NoSuchShaFound if sha1o.nil? || sha1o.empty? || !sha1o.is_a?(String)
sha1 = [sha1o.chomp].pack("H*")
# try packs
- Read upRead up
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 load_packs
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def load_packs(path)
@loaded_packs << path
return if !File.exists?(path)
Dir.open(path) do |dir|
dir.each do |entry|
- Read upRead up
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 load_alternate_loose
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def load_alternate_loose(pathname)
# load alternate loose, too
each_alternate_path pathname do |path|
next if @loaded.include?(path)
next if !File.exist?(path)
- Read upRead up
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 rev_list
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def rev_list(sha, options)
if sha.is_a? Array
(end_sha, sha) = sha
end
- Read upRead up
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 get_raw_tree
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_raw_tree(sha, recursive = false)
o = get_raw_object_by_sha1(sha)
if o.type == :commit
tree = get_object_by_sha1(sha).tree
elsif o.type == :tag
- Read upRead up
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if append
mod_tree = []
tree.each do |ent|
(info, fpath) = ent.split("\t")
mod_tree << [info, File.join(append, fpath)].join("\t")
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if append
mod_tree = []
tree.each do |ent|
(info, fpath) = ent.split("\t")
mod_tree << [info, File.join(append, fpath)].join("\t")
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76