Showing 132 of 132 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
protected void initOptions() {
opt.addOption(ARG_INPUT, true,
"(required) The input file to use (in comma-delimited format, ie. helloworld.input)");
opt.addOption(ARG_QUESTION, true,
"(required) The question file to use (ie. helloworld.question)");
- 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 87.
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
Method runCommand
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected void runCommand(CommandLine cmdLine) throws Exception {
if (!cmdLine.hasOption(ARG_QUALTYPE) &&
!cmdLine.hasOption(ARG_INPUT_FILE)) {
log.error("Either -" + ARG_QUALTYPE + " or -" + ARG_INPUT_FILE + " must be passed");
System.exit(-1);
Method runCommand
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected void runCommand(CommandLine cmdLine) throws Exception {
if (!cmdLine.hasOption(ARG_QUALTYPE) &&
!cmdLine.hasOption(ARG_INPUT_FILE)) {
log.error("Either -" + ARG_QUALTYPE + " or -" + ARG_INPUT_FILE + " should be passed");
Method getHits
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private String[] getHits() {
HIT[] hits = null;
List<String> ret = new ArrayList<String>();
SearchHITsResult result = null;
String[] responseGroup = new String [] { "Minimal", "HITDetail" };
- 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 getSummary
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public Map<String, List<String>> getSummary(String resultsFile) throws ParseException {
// hitid is always required.
String[] requiredFields = new String[]{
"annotation", "Answer.inappropriate", "assignments"
Method rewriteHeaders
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void rewriteHeaders(String source, String destination) throws IOException {
BufferedReader reader = null;
Writer writer = null;
String newline = System.getProperty("line.separator");
Function update
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function update() {
$.ajax({
url:'https://moocchat.herokuapp.com/get_current_timestamp_utc/',
dataType: 'jsonp',
type: 'GET',
Function sendMessages
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
sendMessages: function() {
var self = this;
if(this.isBoth()){
this.sendChatMessageButton.click(function(event) {
event.preventDefault();
Method sessions_show
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def sessions_show
eventlog_sessions = eventlog_sessions(EventLog.where(created_at: parse_datetime_picker_date(params[:datetime_start])..parse_datetime_picker_date(params[:datetime_end])))
@sessions = []
eventlog_sessions.each do |session_events|
Function showWelcomeMessage
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
showWelcomeMessage: function(){
if (this.group.length == 1) {
this.showMessage("No one is currently available to chat with you. You may use this chatroom to reflect on the question. Click the end button above when done.", "system");
} else if (this.group.length == 2) {
var you_learner = '';
Method parseHitAssignments
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static Map<String, List<String[]>> parseHitAssignments(
String resultsFile, String[] requiredFields, int[] fieldIndicesPlaceholder, char fieldSeparator) {
Map<String, List<String[]>> hitAssignments = new LinkedHashMap<String, List<String[]>>();
try {
Method runCommand
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected void runCommand(CommandLine cmdLine) throws Exception {
if (!cmdLine.hasOption(QUAL_TYPE) &&
!cmdLine.hasOption(INPUT_FILE)) {
log.error("Either -" + QUAL_TYPE + " or -" + INPUT_FILE + " should be passed");
Method getHits
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private String[] getHits() {
HIT[] hits = null;
List<String> ret = new ArrayList<String>();
SearchHITsResult result = null;
String[] responseGroup = new String [] { "Minimal", "HITDetail" };
Function keyboardEvent
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
keyboardEvent: function(type, options) {
var evt;
var e = $.extend({ bubbles: true, cancelable: true, view: window,
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
Method approveAssignmentsInFile
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public void approveAssignmentsInFile(String fileName) throws IOException {
if (fileName == null) {
throw new IllegalArgumentException("fileName must not be null");
}
Method getFieldValuesFromFile
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected String[] getFieldValuesFromFile(String fileName, String fieldName) throws IOException {
HITDataCSVReader csvReader = new HITDataCSVReader(fileName);
// check that we have a header
- 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 approveHitsInFile
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public void approveHitsInFile(String fileName) throws IOException {
if (fileName == null) {
throw new IllegalArgumentException("fileName must not be null");
}
- 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 getHeaderRow
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private String[] getHeaderRow(HITResults r) {
if (headerFields == null) {
headerFields = new ArrayList<String>();
for (HITProperties.HITField field : HITProperties.HIT_FIELDS) {
- 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 ensure_setup_socket_for
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def ensure_setup_socket_for(env)
channel, my_position, my_id = channel_and_position_from_url(env['ORIGINAL_FULLPATH'])
unless @groups.has_key?(channel) && @groups[channel][my_position]
ws = Faye::WebSocket.new(env, nil, {ping: KEEPALIVE_TIME })
@groups[channel] ||= []
- 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
Function initialize
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
initialize: function(chatGroup,taskid,rails_mode, type) {
this.type = type;
if(typeof chatGroup == "number"){
this.group = [chatGroup];
} 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"