@TheSoggy 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
Example from src/main/java/duke/Duke.java
lines 18-18
:
private boolean tasksEnd = false;
Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
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
No easy-to-detect issues ๐
Aspect: Method Length
Example from src/main/java/duke/Parser.java
lines 51-150
:
public static Command parseCommand(String input) throws DukeException {
String[] inputs = input.split(" ", 2);
CommandType commandType = CommandType.fromString(inputs[0].toUpperCase());
if (commandType == null) {
throw new DukeException("Invalid command: Please try again.");
}
String description;
switch (commandType) {
case BYE:
return new ByeCommand();
case LIST:
return new ListCommand();
case EMPTY:
return new EmptyCommand();
case MARK:
if (inputs.length == 1) {
throw new DukeException("Wrong number of arguments.");
}
try {
int index = Integer.parseInt(inputs[1]) - 1;
return new SetDoneCommand(index, true);
} catch (NumberFormatException e) {
throw new DukeException("Invalid argument: Index of task should be a number.");
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Invalid argument: Index of task should be between 1 and the number of tasks.");
}
case UNMARK:
if (inputs.length == 1) {
throw new DukeException("Wrong number of arguments.");
}
try {
int index = Integer.parseInt(inputs[1]) - 1;
return new SetDoneCommand(index, false);
} catch (NumberFormatException e) {
throw new DukeException("Invalid argument: Index of task should be a number.");
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Invalid argument: Index of task should be between 1 and the number of tasks.");
}
case TODO:
if (inputs.length == 1) {
throw new DukeException("Wrong number of arguments.");
}
description = inputs[1];
if (description.length() == 0) {
throw new DukeException("Invalid argument: Description cannot be empty.");
}
return new AddTaskCommand(new TodoTask(description, false));
case DEADLINE:
if (inputs.length == 1) {
throw new DukeException("Wrong number of arguments.");
}
try {
description = inputs[1].substring(0, inputs[1].indexOf(" /by "));
if (description.length() == 0) {
throw new DukeException("Invalid argument: Description cannot be empty.");
}
String deadline = inputs[1].substring(inputs[1].indexOf(" /by ") + 5);
if (deadline.length() == 0) {
throw new DukeException("Invalid argument: Deadline cannot be empty.");
}
return new AddTaskCommand(new DeadlineTask(description, Parser.parseDateTime(deadline), false));
} catch (StringIndexOutOfBoundsException e) {
throw new DukeException("Invalid argument: Use /by flag to specify the deadline of the task");
}
case EVENT:
if (inputs.length == 1) {
throw new DukeException("Wrong number of arguments.");
}
try {
description = inputs[1].substring(0, inputs[1].indexOf(" /at "));
if (description.length() == 0) {
throw new DukeException("Invalid argument: Description cannot be empty.");
}
String time = inputs[1].substring(inputs[1].indexOf(" /at ") + 5);
if (time.length() == 0) {
throw new DukeException("Invalid argument: Event time cannot be empty.");
}
return new AddTaskCommand(new EventTask(description, Parser.parseDateTime(time), false));
} catch (StringIndexOutOfBoundsException e) {
throw new DukeException("Invalid argument: Use /at flag to specify the date and time of the event.");
}
case DELETE:
if (inputs.length == 1) {
throw new DukeException("Wrong number of arguments.");
}
try {
int index = Integer.parseInt(inputs[1]) - 1;
return new DeleteTaskCommand(index);
} catch (NumberFormatException e) {
throw new DukeException("Invalid argument: Index of task should be a number.");
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Invalid argument: Index of task should be between 1 and the number of tasks.");
}
default:
throw new DukeException("Invalid command: Please try again.");
}
}
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
No easy-to-detect issues ๐
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.