Skip to content

Sharing iP code quality feedback [for @cyhni] #1

Description

@soc-se-bot

@cyhni 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/test/java/billy/ui/UiTest.java lines 14-14:

    // public void printIntroduction_introductionMessage_success() throws IOException {

Example from src/test/java/billy/ui/UiTest.java lines 15-15:

    //     Ui ui = new Ui();

Example from src/test/java/billy/ui/UiTest.java lines 16-16:

    //     ui.printIntroduction();;

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/billy/parser/Parser.java lines 33-162:

    private static final Pattern DATETIME_PATTERN = Pattern.compile("\\d{2}-\\d{2}\\-\\d{4} \\d{4}");

    /**
     * Parses the user command and returns the corresponding Command object.
     * The user command must be in the format "command [description] [date]".
     * The date must be in the format "dd-MM-yyyy HHmm".
     *
     * @param userCmd The user command to be parsed.
     * @param tasksList The list of tasks.
     * @param ui The user interface.
     * @return The Command object corresponding to the user command.
     * @throws BillyException If an error occurs during parsing.
     * @throws DateTimeException If an error occurs during date parsing.
     * @throws IOException If an error occurs during I/O.
     */
    public static Command parseCommand(String userCmd, TasksList tasksList, Ui ui)
            throws BillyException,
            DateTimeException,
            IOException {
        Command command;
        String[] commandStrings = userCmd.split(" ");

        switch (commandStrings[0]) {
        case "list":
            command = new ListCommand();
            break;

        case "mark":
            if (commandStrings.length == 1) {
                throw new BillyFieldErrorException("mark");
            } else if (Integer.parseInt(commandStrings[1]) > tasksList.getSize()) {
                throw new BillyUnkownTaskNumException(commandStrings[1]);
            }

            command = new MarkCommand(Integer.parseInt(commandStrings[1]));
            break;

        case "unmark":
            if (commandStrings.length == 1) {
                throw new BillyFieldErrorException("mark");
            } else if (Integer.parseInt(commandStrings[1]) > tasksList.getSize()) {
                throw new BillyUnkownTaskNumException(commandStrings[1]);
            }

            command = new UnmarkCommand(Integer.parseInt(commandStrings[1]));
            break;

        case "todo":
            if (commandStrings.length == 1) {
                throw new BillyFieldErrorException("todo");
            }

            command = new TodoCommand(new Todo(userCmd.substring(commandStrings[0].length() + 1)));
            break;

        case "deadline":
            String[] deadlineSplit = userCmd.split(" /by ");
            if (deadlineSplit.length <= 1 || deadlineSplit[0].length() == commandStrings[0].length()) {
                throw new BillyFieldErrorException("deadline");
            }

            String deadlineDescription = deadlineSplit[0].substring(commandStrings[0].length() + 1);
            String deadlineDate = deadlineSplit[1];
            if (deadlineDescription.equals("") || deadlineDate.equals("")) {
                throw new BillyFieldErrorException("deadline");
            }

            LocalDateTime deadlineParsedDate = parseDate(deadlineDate);
            if (deadlineParsedDate == null) {
                throw new DateTimeException("Billy does not understand the date format..."
                        + "\nPlease use dd-MM-yyyy HHmm format...");
            }

            command = new DeadlineCommand(new Deadline(deadlineDescription, deadlineParsedDate));
            break;

        case "event":
            String[] eventSplit = userCmd.split(" /from ");
            String[] eventSplit2 = userCmd.split(" /to ");
            String[] eventSplitCheck = eventSplit[1].split(" /to ");
            if (eventSplit.length <= 1
                    || eventSplit2.length <= 1
                    || eventSplit[0].length() == commandStrings[0].length()
                    || eventSplitCheck.length == 1) {
                throw new BillyFieldErrorException("event");
            }

            String eventDescription = eventSplit[0].substring(commandStrings[0].length() + 1);
            String eventFrom = eventSplit[1].substring(0, eventSplit[1].length() - eventSplit2[1].length() - 5);
            String eventTo = eventSplit2[1];
            if (eventDescription.equals("") || eventFrom.equals("") || eventTo.equals("")) {
                throw new BillyFieldErrorException("event");
            }

            LocalDateTime eventParsedFrom = parseDate(eventFrom);
            LocalDateTime eventParsedTo = parseDate(eventTo);
            if (eventParsedFrom == null || eventParsedTo == null) {
                throw new DateTimeException("Billy does not understand the date format..."
                        + "\nPlease use dd-MM-yyyy HHmm format...");
            } else if (eventParsedFrom.isAfter(eventParsedTo)) {
                throw new DateTimeException("Please ensure that the start date is before the end date...");
            }

            command = new EventCommand(new Event(eventDescription, eventParsedFrom, eventParsedTo));
            break;

        case "delete":
            if (commandStrings.length == 1) {
                throw new BillyFieldErrorException("delete");
            } else if (Integer.parseInt(commandStrings[1]) > tasksList.getSize()) {
                throw new BillyUnkownTaskNumException(commandStrings[1]);
            }

            command = new DeleteCommand(Integer.parseInt(commandStrings[1]) - 1,
                    tasksList.getTask(Integer.parseInt(commandStrings[1]) - 1));
            break;

        case "find":
            if (commandStrings.length == 1) {
                throw new BillyFieldErrorException("find");
            }

            command = new FindCommand(commandStrings[1]);
            break;

        default:
            throw new BillyUnknownException();
        }
        return command;
    }

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/billy/Billy.java lines 62-66:

    /**
     * The main entry point of the Billy application.
     *
     * @param args The command line arguments.
     */

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 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.

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