-
Notifications
You must be signed in to change notification settings - Fork 0
Description
@matthanfoo 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/Chatty.java lines 18-18:
boolean running = true;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/running/Storage.java lines 18-62:
public ArrayList<Task> load() {
File file = new File(filename);
ArrayList<Task> userInputs = new ArrayList<Task>();
if (file.exists()) {
System.out.println("File exists, reading contents...");
// read CSV into Task ArrayList
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
String line;
while ((line = br.readLine()) != null) {
String[] row = line.split(","); // Splitting by comma
if (row[0].equals("T")) {
Todo t = new Todo(row[1]);
if (row[2].equals("X")) { t.mark(); }
userInputs.add(t);
} else if (row[0].equals("E")) {
Event e = new Event(row[1], LocalDateTime.parse(row[3], dateTimeFormatter), LocalDateTime.parse(row[3], dateTimeFormatter));
if (row[2].equals("X")) { e.mark(); }
userInputs.add(e);
} else if (row[0].equals("D")) {
Deadline d = new Deadline(row[1], LocalDateTime.parse(row[3], dateTimeFormatter));
if (row[2].equals("X")) { d.mark(); }
userInputs.add(d);
}
}
} catch (IOException e) {
System.out.println("Error reading the file.");
e.printStackTrace();
}
} else {
System.out.println("File does not exist, creating new CSV...");
try (FileWriter writer = new FileWriter(filename)) {
// writer.append("Type, Title, Done, Date1, Date2\n"); // CSV Header
System.out.println("CSV file written successfully.");
} catch (IOException e) {
System.out.println("Error writing to file.");
e.printStackTrace();
}
}
return userInputs;
}Example from src/main/java/running/Parser.java lines 85-139:
public boolean execute(TaskList tasks, String command, UI ui) {
String printText = "";
if (command.equalsIgnoreCase("bye")) {
return false;
} else if (command.equalsIgnoreCase("list")) {
printText = tasks.list();
} else if (command.equalsIgnoreCase("today")) {
printText = tasks.today();
} else if (command.contains("unmark")) {
int markIndex = parseMark(command);
printText = markIndex < 0 ? "Invalid input" : tasks.unmarkTask(markIndex);
} else if (command.contains("mark")) {
int markIndex = parseMark(command);
printText = markIndex < 0 ? "Invalid input" : tasks.markTask(markIndex);
} else if (command.contains("delete")) {
int markIndex = parseMark(command);
printText = markIndex < 0 ? "Invalid input" : tasks.deleteTask(markIndex);
} else if (command.contains("todo")) {
String todoTitle = parseTitle(command, "todo");
printText = todoTitle.equals("") ? "Invalid task title" : tasks.createTodo(todoTitle);
} else if (command.contains("event")) {
String eventTitle = parseTitle(command, "event");
if (eventTitle.equals("")) {
printText = "Invalid event title";
} else {
String fromString = parseRegex(command, "/from\s*(.*?)\s+/");
String toString = parseRegex(command, "/to\\s*(.*)");
try {
fromString = readInputIntoIso(fromString);
toString = readInputIntoIso(toString);
printText = tasks.createEvent(eventTitle, fromString, toString);
} catch (Exception e){
printText = e.getMessage();
}
}
} else if (command.contains("deadline")) {
String deadlineTitle = parseTitle(command, "deadline");
if (deadlineTitle.equals("")) {
printText = "Invalid deadline title";
} else {
String byString = parseRegex(command, "/by\\s*(.*)");
try {
byString = readInputIntoIso(byString);
printText = tasks.createDeadline(deadlineTitle, byString);
} catch (Exception e){
printText = e.getMessage();
}
}
} else {
printText = "Invalid command";
}
ui.print(printText);
return true;
}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 Messages
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.