@sugiyem 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
No easy-to-detect issues ๐
Aspect: Method Length
Example from src/main/java/duke/parser/Parser.java
lines 45-83
:
public Command parseText(String text) throws DukeException {
List<String> commands = Arrays.stream(text.trim().split(" ", 2))
.map(String::trim)
.collect(Collectors.toList());
String mainCommand = commands.get(0);
String description = commands.size() > 1 ? commands.get(1) : "";
if (mainCommand.equals("bye")) {
this.isListening = false;
return new ByeCommand();
} else if (mainCommand.equals("list")) {
return new ListCommand();
} else if (mainCommand.equals("mark")) {
return new MarkCommand(description);
} else if (mainCommand.equals("unmark")) {
return new UnmarkCommand(description);
} else if (mainCommand.equals("delete")) {
return new DeleteCommand(description);
} else if (mainCommand.equals("todo")) {
return new ToDoCommand(description);
} else if (mainCommand.equals("deadline")) {
return new DeadlineCommand(description);
} else if (mainCommand.equals("event")) {
return new EventCommand(description);
} else if (mainCommand.equals("find")) {
return new FindCommand(description);
} else if (mainCommand.equals("at")) {
return new AtCommand(description);
} else if (mainCommand.equals("any")) {
return new AnyCommand(description);
} else if (mainCommand.equals("all")) {
return new AllCommand(description);
} else if (mainCommand.isEmpty()) {
throw new EmptyCommandException();
} else {
throw new DukeException();
}
}
Example from src/main/java/duke/storage/Storage.java
lines 61-111
:
public TaskList loadTasksInStorage() {
TaskList loadedTaskList;
try {
List<Task> loadedTasks = new ArrayList<>();
BufferedReader storageReader = new BufferedReader(new FileReader(this.filePath));
String taskString = storageReader.readLine();
while (taskString != null && !taskString.isEmpty()) {
int dateSeparatorIndex = taskString.lastIndexOf("|");
int tagsIndex = taskString.indexOf("#");
String taskType = taskString.substring(0, 1);
String taskStatus = taskString.substring(2, 3);
String description = dateSeparatorIndex == 3
? taskString.substring(4, tagsIndex)
: taskString.substring(4, dateSeparatorIndex);
String taskDate = taskString.substring(dateSeparatorIndex + 1, tagsIndex);
String[] tags;
if (tagsIndex == taskString.length() - 1) {
tags = new String[0];
} else {
tags = Arrays.stream(taskString.substring(tagsIndex + 1).split(","))
.map(String::trim)
.filter(text -> !text.isEmpty())
.toArray(String[]::new);
}
Task currentLoadedTask = taskType.equals("D")
? new Deadline(description, taskDate, tags)
: taskType.equals("E")
? new Event(description, taskDate, tags)
: new ToDo(description, tags);
if (taskStatus.equals("X")) {
currentLoadedTask.markAsFinished();
}
loadedTasks.add(currentLoadedTask);
taskString = storageReader.readLine();
}
storageReader.close();
loadedTaskList = new TaskList(loadedTasks);
} catch (DukeException | IOException error) {
loadedTaskList = new TaskList();
}
return loadedTaskList;
}
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/storage/Storage.java
lines 113-118
:
/**
* Save the list of string to Duke's storage.
*
* @param taskListString the list of string to be saved.
* @throws DukeException If the storage fails to save the list of string.
*/
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.