@linustws We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
No easy-to-detect issues ๐
Aspect: Naming boolean variables/methods
No easy-to-detect issues ๐
Aspect: Brace Style
No easy-to-detect issues ๐
Aspect: Package Name Style
No easy-to-detect issues ๐
Aspect: Class Name Style
No easy-to-detect issues ๐
Aspect: Dead Code
Example from src/main/java/duke/Duke.java
lines 35-35
:
Example from src/test/java/duke/DukeTest.java
lines 45-45
:
Example from src/test/java/duke/DukeTest.java
lines 66-66
:
// assertEquals(expectedOutput, out.toString());
Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/duke/command/Parser.java
lines 103-210
:
public static Command parse(String fullCommand) throws DukeException {
String[] parts = fullCommand.split(" ", 2);
int indexInput;
switch(parts[0].trim()) {
case "todo":
if (parts.length != 2 || parts[1].trim().isEmpty()) {
throw new DukeException("Command todo has to be followed by a description.");
}
Todo todo = new Todo(parts[1].trim());
return new Command.AddCommand(todo);
case "deadline":
String deadlineError = "Command deadline has to have a string and date separated with a /by keyword.";
if (parts.length != 2 || parts[1].trim().isEmpty()) {
throw new DukeException(deadlineError);
}
String[] d_parts = parts[1].split(" /by ", 2);
if (d_parts.length < 2 || d_parts[0].trim().isEmpty() || d_parts[1].trim().isEmpty()) {
throw new DukeException(deadlineError);
}
LocalDateTime deadlineDateTime = stringToDateTime(d_parts[1].trim());
Deadline deadline = new Deadline(d_parts[0].trim(), deadlineDateTime);
return new Command.AddCommand(deadline);
case "event":
String eventError = "Command event has to have a string and 2 dates separated with /from and /to keywords.";
if (parts.length != 2 || parts[1].trim().isEmpty()) {
throw new DukeException(eventError);
}
String[] e_parts = parts[1].split(" /from | /to ", 3);
if (e_parts.length < 3 || e_parts[0].trim().isEmpty() || e_parts[1].trim().isEmpty() || e_parts[2].trim().isEmpty()) {
throw new DukeException(eventError);
}
LocalDateTime startDateTime = stringToDateTime(e_parts[1].trim());
LocalDateTime endDateTime = stringToDateTime(e_parts[2].trim());
// Checks if start date is before end date
if (endDateTime.isBefore(startDateTime)) {
throw new DukeException("End date cannot be before start date.");
}
Event event = new Event(e_parts[0].trim(), startDateTime, endDateTime);
return new Command.AddCommand(event);
case "list":
return new Command.ListCommand();
case "mark":
String markError = "Command mark has to be followed by an integer.";
if (parts.length != 2 || parts[1].trim().isEmpty()) { // 2nd arg not entered
throw new DukeException(markError);
}
try {
indexInput = Integer.parseInt(parts[1].trim());
} catch (NumberFormatException e) {
throw new DukeException(markError);
}
return new Command.MarkCommand(indexInput - 1);
case "unmark":
String unmarkError = "Command unmark has to be followed by an integer.";
if (parts.length != 2 || parts[1].trim().isEmpty()) { // 2nd arg not entered
throw new DukeException(unmarkError);
}
try {
indexInput = Integer.parseInt(parts[1].trim());
} catch (NumberFormatException e) {
throw new DukeException(unmarkError);
}
return new Command.UnmarkCommand(indexInput - 1);
case "delete":
String deleteError = "Command delete has to be followed by an integer.";
if (parts.length != 2 || parts[1].trim().isEmpty()) { // 2nd arg not entered
throw new DukeException(deleteError);
}
try {
indexInput = Integer.parseInt(parts[1].trim());
} catch (NumberFormatException e) {
throw new DukeException(deleteError);
}
return new Command.DeleteCommand(indexInput - 1);
case "filter":
if (parts.length != 2 || parts[1].trim().isEmpty()) {
throw new DukeException("Command filter has to be followed by a keyword(s) separated with commas.");
}
String[] stringKeywords = parts[1].trim().split(",");
String[] validKeywords = new String[stringKeywords.length];
for (int i = 0; i < stringKeywords.length; i++) {
validKeywords[i] = stringKeywords[i].trim();
}
return new Command.FilterCommand(validKeywords);
case "filterdate":
if (parts.length != 2 || parts[1].trim().isEmpty()) {
throw new DukeException("Command filterdate has to be followed by date(s) separated with commas.");
}
String[] stringDates = parts[1].trim().split(",");
LocalDate[] validDates = new LocalDate[stringDates.length];
for (int i = 0; i < stringDates.length; i++) {
validDates[i] = stringToDate(stringDates[i].trim());
}
return new Command.FilterDateCommand(validDates);
case "sort":
return new Command.SortCommand();
case "sortdate":
return new Command.SortDateCommand();
case "sorttask":
return new Command.SortTaskCommand();
case "sortdone":
return new Command.SortDoneCommand();
case "bye":
return new Command.ExitCommand();
default:
throw new DukeException("I'm sorry, but I don't know what that means :-(");
}
}
Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues ๐
Aspect: Header Comments
Example from src/main/java/duke/task/TaskList.java
lines 41-46
:
/**
* Filter tasks by keywords.
*
* @param keywords Keywords to filter tasks by.
* @return TaskList of filtered tasks.
*/
Example from src/main/java/duke/task/TaskList.java
lines 55-60
:
/**
* Filter tasks by their dates.
*
* @param dates Dates to filter tasks by.
* @return TaskList of filtered tasks.
*/
Example from src/main/java/duke/ui/Ui.java
lines 20-22
:
Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues ๐
Aspect: Binary files in repo
No easy-to-detect issues ๐
โน๏ธ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected]
if you want to follow up on this post.