Method revisions
has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring. Open
def revisions(path, identifier_from, identifier_to, options = {}) # rubocop:disable Style/OptionHash
revs = Revisions.new
cmd_args = %w[log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents --stdin]
cmd_args << '--no-renames' if self.class.client_version_above? [2, 9]
cmd_args << '--reverse' if options[:reverse]
- 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
File xitolite_adapter.rb
has 440 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'redmine/scm/adapters/abstract_adapter'
# XitoliteAdapter inherits from GitAdapter but some classes which are define directly in GitAdapter are not inherited
# (GitBranch, ScmCommandAborted and maybe others) so it raises NameError exception.
# To fix this I had to reimplement (copy/past) the whole GitAdapter class in XitoliteAdapter...
Method entries
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
def entries(path = nil, identifier = nil, **options)
path ||= ''
p = scm_iconv @path_encoding, 'UTF-8', path
entries = Entries.new
cmd_args = %w[ls-tree -l]
- 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 XitoliteAdapter
has 35 methods (exceeds 20 allowed). Consider refactoring. Open
class XitoliteAdapter < AbstractAdapter
# Git executable name
XITOLITE_BIN = Redmine::Configuration['scm_git_command'] || 'git'
GIT_DEFAULT_BRANCH_NAMES = %w[main master].freeze
Method revisions
has 97 lines of code (exceeds 25 allowed). Consider refactoring. Open
def revisions(path, identifier_from, identifier_to, options = {}) # rubocop:disable Style/OptionHash
revs = Revisions.new
cmd_args = %w[log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents --stdin]
cmd_args << '--no-renames' if self.class.client_version_above? [2, 9]
cmd_args << '--reverse' if options[:reverse]
Method lastrev
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def lastrev(path, rev)
return if path.nil?
cmd_args = %w[log --no-color --encoding=UTF-8 --date=iso --pretty=fuller --no-merges -n 1]
cmd_args << '--no-renames' if self.class.client_version_above? [2, 9]
- 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 annotate
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def annotate(path, identifier = nil)
identifier = 'HEAD' if identifier.blank?
cmd_args = %w[blame --encoding=UTF-8]
cmd_args << '-p' << identifier << '--' << scm_iconv(@path_encoding, 'UTF-8', path)
blame = Annotate.new
Method entries
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def entries(path = nil, identifier = nil, **options)
path ||= ''
p = scm_iconv @path_encoding, 'UTF-8', path
entries = Entries.new
cmd_args = %w[ls-tree -l]
Method diff
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def diff(path, identifier_from, identifier_to = nil, **opts)
path ||= ''
cmd_args = []
if identifier_to
cmd_args << 'diff' << '--no-color' << identifier_to << identifier_from
- 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 annotate
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def annotate(path, identifier = nil)
identifier = 'HEAD' if identifier.blank?
cmd_args = %w[blame --encoding=UTF-8]
cmd_args << '-p' << identifier << '--' << scm_iconv(@path_encoding, 'UTF-8', path)
blame = Annotate.new
- 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 branches
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def branches
return @branches if @branches
@branches = []
cmd_args = %w[branch --no-color --verbose --no-abbrev]
- 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 valid_name?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def valid_name?(name)
return false unless name.is_a? String
return false if name.start_with? '-', '/', 'refs/heads/', 'refs/remotes/'
return false if name == 'HEAD'
- 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 initialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(url, root_url = nil, login = nil, password = nil, path_encoding = nil)
Method entry
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def entry(path = nil, identifier = nil)
parts = path.to_s.split(%r{[/\\]}).select(&:present?)
search_path = parts[0..-2].join('/')
search_name = parts[-1]
if search_path.blank? && search_name.blank?
- 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
revision = Revision.new({ identifier: changeset[:commit],
scmid: changeset[:commit],
author: changeset[:author],
time: Time.parse(changeset[:date]),
message: changeset[:description],
- 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 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
- 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
revision = Revision.new({ identifier: changeset[:commit],
scmid: changeset[:commit],
author: changeset[:author],
time: Time.parse(changeset[:date]),
message: changeset[:description],
- 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 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
- 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