Skip to content

Sharing iP code quality feedback [for @seksek13] #3

Description

@nus-se-bot

@seksek13 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/Main.java lines 24-24:

            //ui.showWelcomeMessage();

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/duke/Duke.java lines 35-68:

    public String getResponse(String input) throws DukeException {

        try {
            String[] commands = Parser.parse(input.toLowerCase(Locale.ROOT));
            if (commands[0].equals("bye")) {
                return exitSystem();
            } else if (commands[0].equals("list")) {
                return listTask();
            } else if (commands[0].equals("mark")) {
                int indexOfTask = Integer.parseInt(commands[1]);
                return markTask(indexOfTask);
            } else if (commands[0].equals("unmark")) {
                int indexOfTask = Integer.parseInt(commands[1]);
                return unmarkTask(indexOfTask);
            } else if (commands[0].equals("todo")) {
                return addTodoTask(commands[1]);
            } else if (commands[0].equals("event")) {
                return addEventTask(commands[1], commands[2]);
            } else if (commands[0].equals("deadline")) {
                return addDeadlineTask(commands[1], commands[2]);
            } else if (commands[0].equals("delete")) {
                int index = Integer.parseInt(commands[1]);
                return deleteTask(index);
            } else if (commands[0].equals("find")) {
                return findTasks(commands[1]);
            } else if (commands[0].equals("reminder")) {
                return reminder(commands[1]);
            } else {
                return "You have entered an invalid command! :(";
            }
        } catch (DukeException | IOException | IllegalArgumentException e) {
            return ui.showError(e.getMessage());
        }
    }

Example from src/main/java/duke/Parser.java lines 20-105:

    public static String[] parse(String command) throws DukeException {

        HashSet<String> commandsWithArgs = new HashSet<>();
        commandsWithArgs.add("mark");
        commandsWithArgs.add("unmark");
        commandsWithArgs.add("delete");
        commandsWithArgs.add("todo");
        commandsWithArgs.add("deadline");
        commandsWithArgs.add("event");
        commandsWithArgs.add("find");

        if (commandsWithArgs.contains(command)) {
            String[] splitedcmd = command.split(" ");
            if (splitedcmd.length < 2) {
                String message = String.format("OOPS! "
                        + "The description of a %s cannot be empty.", command);
                throw new DukeException(message);
            }
        }

        if (command.equals("bye")) {
            String[] descriptions = new String[] { "bye"};
            return descriptions;
        } else if (command.equals("list")) {
            String[] descriptions = new String[] { "list" };
            return descriptions;
        } else if (command.startsWith("mark")) {
            String[] cmd = command.split(" ");
            String[] descriptions = new String[] { "mark", cmd[1]};
            return descriptions;
        } else if (command.startsWith("unmark")) {
            String[] cmd = command.split(" ");
            String[] descriptions = new String[] { "unmark", cmd[1] };
            return descriptions;
        } else if (command.startsWith("delete")) {
            String[] cmd = command.split(" ");
            String[] descriptions = new String[] { "delete", cmd[1] };
            return descriptions;
        } else if (command.startsWith("todo")) {
            String[] cmds = command.split("todo ");
            String[] descriptions = new String[] { "todo", cmds[1] };
            return descriptions;
        } else if (command.startsWith("deadline")) {
            String[] cmd = command.split("deadline ");
            String[] task = cmd[1].split("/by ");
            boolean isDateEmpty = task[1].isEmpty();
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN);
            LocalDateTime deadlineDate = parseDateTime(task[1], dtf);
            if (deadlineDate == null || isDateEmpty) {
                throw new DukeException("'" + task[1] + "' is in wrong format! "
                        + "Please enter date and time as dd/MM/yyyy HH:mm");
            }
            String[] descriptions = new String[] { "deadline", task[0], task[1] };
            return descriptions;
        } else if (command.startsWith("event")) {
            String[] cmd = command.split("event ");
            String[] task = cmd[1].split("/at ");
            boolean isDateEmpty = task[1].isEmpty();
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN);
            LocalDateTime deadlineDate = parseDateTime(task[1], dtf);
            if (deadlineDate == null || isDateEmpty) {
                throw new DukeException("'" + task[1] + "' is in wrong format! "
                        + "Please enter date and time as dd/MM/yyyy HH:mm");
            }
            String[] descriptions = new String[] { "event", task[0], task[1] };
            return descriptions;

        } else if (command.startsWith("find")) {
            String[] cmd = command.split("find ");
            String[] descriptions = new String[]{ "find", cmd[1]};
            return descriptions;
        } else if (command.startsWith("reminder")) {
            String[] cmd = command.split("reminder ");
            boolean isDateEmpty = cmd[1].isEmpty();
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN);
            LocalDateTime deadlineDate = parseDateTime(cmd[1], dtf);
            if (deadlineDate == null || isDateEmpty) {
                throw new DukeException("'" + cmd[1] + "' is in wrong format! "
                        + "Please enter date and time as dd/MM/yyyy HH:mm");
            }
            String[] descriptions = new String[] { "reminder", cmd[1]};
            return descriptions;
        } else {
            throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-(");
        }
    }

Example from src/main/java/duke/Storage.java lines 28-91:

    public ArrayList<Task> load() throws IOException {
        ArrayList<Task> tasks = new ArrayList<Task>(100);
        boolean isCorrectLength;
        DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
        try {
            File file = new File("./data/duke.txt");
            Scanner fileData = new Scanner(file);
            while (fileData.hasNextLine()) {
                String data = fileData.nextLine();
                String[] dataSplited = data.split(",");
                String taskType = dataSplited[0].toUpperCase();
                boolean isDone = dataSplited[1].equals("1");

                switch (taskType) {
                case "T":
                    isCorrectLength = (dataSplited.length == 3);
                    if (!isCorrectLength) {
                        System.out.println("data: " + data + " not in correct format!");
                        break;
                    }
                    Task todo = new Todo(dataSplited[2], isDone);
                    tasks.add(todo);
                    break;
                case "D":
                    isCorrectLength = (dataSplited.length == 4);
                    if (!isCorrectLength) {
                        System.out.println("data: " + data + " not in correct format!");
                        break;
                    }
                    LocalDateTime deadlineDateFormatted = LocalDateTime.parse(dataSplited[3], format);
                    Task deadline = new Deadline(dataSplited[2], deadlineDateFormatted, isDone);
                    tasks.add(deadline);
                    break;
                case "E":
                    isCorrectLength = (dataSplited.length == 4);
                    if (!isCorrectLength) {
                        System.out.println("data: " + data + " not in correct format!");
                        break;
                    }
                    LocalDateTime eventDateFormatted = LocalDateTime.parse(dataSplited[3], format);
                    Task event = new Event(dataSplited[2], eventDateFormatted, isDone);
                    tasks.add(event);
                    break;
                default:
                    System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(");
                    break;
                }
            }
            fileData.close();
            return tasks;
        } catch (FileNotFoundException e) {
            assert filePath != null : "File path is not supposed to be null.";

            File directory = new File("./data");
            if (!directory.exists()) {
                directory.mkdir();
            }
            File file = new File(filePath);
            if (!file.exists()) {
                file.createNewFile();
            }
            return tasks;
        }
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten 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/Deadline.java lines 26-30:

    /**
     * Parse date into MMM dd yyyy format
     *
     * @return date in MMM dd yyyy hh:mm a format
     */

Example from src/main/java/duke/Duke.java lines 32-34:

    /**
     * Method to run entire programme
     */

Example from src/main/java/duke/Event.java lines 19-23:

    /**
     * Parse date into MMM dd yyyy format
     *
     * @return date in MMM dd yyyy hh:mm a format
     */

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 👍

ℹ️ The bot account @nus-se-bot 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions