-
Notifications
You must be signed in to change notification settings - Fork 0
Description
@PyromancerBoom 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/Deadline.java lines 12-12:
// protected String dueDate;Example from src/main/java/duke/TaskRepository.java lines 80-80:
// System.out.println("Your tasks have been loaded from storage.");Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/duke/Parser.java lines 35-112:
public void startOperator() throws BotException, IOException {
while (true) {
System.out.print("> "); // print ">" before user input
String userInputLine = scanner.nextLine();
String[] userInputArray = userInputLine.split(" ");
String command = userInputArray[0];
switch (command) {
case "bye":
Bot.botExitMsg();
return;
case "list":
botListAllTasks();
break;
case "help":
Bot.botHelpMsg();
break;
case "mark":
try {
markTaskHandler(userInputArray);
// save to file
taskRepository.saveTasksToFile(taskList);
} catch (BotException e) {
System.out.println(e.getMessage());
}
break;
case "unmark":
try {
unmarkTaskHandler(userInputArray);
taskRepository.saveTasksToFile(taskList);
} catch (BotException e) {
System.out.println(e.getMessage());
}
break;
case "todo":
try {
handleTodoCommand(userInputArray);
taskRepository.saveTasksToFile(taskList);
} catch (BotException e) {
System.out.println(e.getMessage());
}
break;
case "deadline":
try {
handleDeadlineCommand(userInputArray);
taskRepository.saveTasksToFile(taskList);
} catch (BotException e) {
System.out.println(e.getMessage());
}
break;
case "event":
try {
handleEventCommand(userInputArray);
taskRepository.saveTasksToFile(taskList);
} catch (BotException e) {
System.out.println(e.getMessage());
}
break;
case "delete":
try {
handleDeleteCommand(userInputArray);
taskRepository.saveTasksToFile(taskList);
} catch (BotException e) {
System.out.println(e.getMessage());
}
break;
case "find":
handleFindCommand(userInputArray);
break;
default:
try {
handleInvalidCommand();
} catch (BotException e) {
System.out.println(e.getMessage());
}
}
}
}Example from src/main/java/duke/TaskRepository.java lines 41-86:
public TaskList loadTasks() throws BotException {
try {
BufferedReader reader = new BufferedReader(new FileReader(FILE_PATH));
String line;
while ((line = reader.readLine()) != null) {
String[] taskDetails = line.split("\\|");
String isDone = taskDetails[1].trim();
Boolean isTaskDone = isDone.equals("X");
String taskType = taskDetails[0].trim();
String description = taskDetails[2].trim();
switch (taskType) {
case "T":
taskList.addTodo(description);
if (isTaskDone) {
taskList.getTaskByNum(taskList.getTaskCount()).markAsDone();
}
break;
case "D":
String dueDate = taskDetails[3].trim();
dueDate = dueDate.substring(3).trim();
taskList.addDeadline(description, dueDate);
if (isTaskDone) {
taskList.getTaskByNum(taskList.getTaskCount()).markAsDone();
}
break;
case "E":
String timeBlock = taskDetails[3].trim();
String[] parts = timeBlock.split("to:");
String fromPart = parts[0];
String toPart = parts[1];
String startTime = fromPart.replace("from:", "").trim();
String endTime = toPart.trim();
taskList.addEvent(description, startTime, endTime);
if (isTaskDone) {
taskList.getTaskByNum(taskList.getTaskCount()).markAsDone();
}
break;
}
}
// System.out.println("Your tasks have been loaded from storage.");
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return taskList;
}Example from src/main/java/duke/TimeBlock.java lines 25-67:
public TimeBlock(String description, String fromTime, String toTime) throws BotException {
super(description);
// The various formats that the time can be in
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("d/M/yyyy HHmm");
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm");
DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern("HHmm");
// Check if the time is in the correct format
try {
LocalDateTime.parse(fromTime, formatter1);
this.fromTime = fromTime;
} catch (DateTimeParseException e1) {
try {
LocalDateTime.parse(fromTime, formatter2);
this.fromTime = fromTime;
} catch (DateTimeParseException e2) {
try {
LocalTime.parse(fromTime, formatter3);
this.fromTime = fromTime;
} catch (DateTimeParseException e3) {
throw new BotException(
"Invalid fromTime format. Please use either 'd/M/yyyy HHmm', 'MMM dd yyyy HH:mm' or 'HHmm'.");
}
}
}
try {
LocalDateTime.parse(toTime, formatter1);
this.toTime = toTime;
} catch (DateTimeParseException e1) {
try {
LocalDateTime.parse(toTime, formatter2);
this.toTime = toTime;
} catch (DateTimeParseException e2) {
try {
LocalTime.parse(toTime, formatter3);
this.toTime = toTime;
} catch (DateTimeParseException e3) {
throw new BotException(
"Invalid toTime format. Please use either 'd/M/yyyy HHmm', 'MMM dd yyyy HH:mm' or 'HHmm'.");
}
}
}
}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/Duke.java lines 12-16:
/**
* The main method to start the bot.
* It initializes the bot, prints a greeting, and starts the operator to parse
* user input
*/Example from src/main/java/duke/TaskList.java lines 22-26:
/**
* Method to add a new todo task to the list
*
* @param description The description of the task
*/Example from src/main/java/duke/TaskList.java lines 32-37:
/**
* Method to add a new deadline task to the list
*
* @param description The description of the task
* @param dueDate The due date of the task
*/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
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 cs2103@comp.nus.edu.sg if you want to follow up on this post.