File rugged_repository.rb
has 398 lines of code (exceeds 250 allowed). Consider refactoring. Open
description 'Git repository backend (Using rugged library)'
require 'rugged'
require 'fileutils'
class RuggedRepository < Repository
Class RuggedRepository
has 28 methods (exceeds 20 allowed). Consider refactoring. Open
class RuggedRepository < Repository
CONTENT_EXT = '.content'
ATTRIBUTE_EXT = '.attributes'
class Blob
Method method_missing
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def method_missing(name, *args)
cmd = name.to_s
if cmd =~ /\Agit_/
cmd = $'.tr('_', '-')
args = args.flatten.compact.map(&:to_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_path_version
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def get_path_version(path, version)
check_path(path)
version ||= @git.head.target
version = version.to_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_path_version
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_path_version(path, version)
check_path(path)
version ||= @git.head.target
version = version.to_s
Method get_history
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def get_history(path, skip, limit)
check_path(path)
commits = []
walker = Rugged::Walker.new(@git)
- 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 []=
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def []=(path, object)
raise 'Blank path' if path.blank?
@oid = nil
name, path = path.split('/', 2)
child = get(name)
- 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 delete
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def delete(path)
raise 'Blank path' if path.blank?
@oid = nil
name, path = path.split('/', 2)
child = get(name)
- 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 path_changed?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def path_changed?(c, path)
return true if path.blank?
ref1, ref2, ref3 = nil, nil, nil
(c.parents.empty? && (ref1 ||= oid_by_path(c, path))) || c.parents.any? do |parent|
(ref1 ||= oid_by_path(c, path)) != (oid_by_path(parent, 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 []
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def [](path)
return self if path.blank?
name, path = path.split('/', 2)
child = get(name)
if path && child
- 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 a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def diff(path, from, to)
check_path(path)
commit_from = from && @git.rev_parse(from.to_s)
commit_to = @git.rev_parse(to.to_s)
raise 'Not a commit' unless (!commit_from || Rugged::Commit === commit_from) && Rugged::Commit === commit_to
- 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 expand_tree
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def expand_tree(path)
names = path.split('/')
names.pop
parent = work_tree
names.each do |name|
- 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_version
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_version(version = nil)
if version
commit = @git.rev_parse(version.to_s) rescue nil
commit_to_version(commit)
else
- 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 set_content
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def set_content(path, content)
check_path(path)
expand_tree(path)
object = work_tree[path]
if object && object.type == :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
Identical blocks of code found in 2 locations. Consider refactoring. Open
names.each do |name|
object = parent[name]
break if !object
if object.type == :blob
parent.move(name, name + CONTENT_EXT)
- 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 28.
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