Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing iP code quality feedback [for @blackpanther9229] #4

Open
nus-se-script opened this issue Sep 14, 2024 · 0 comments
Open

Sharing iP code quality feedback [for @blackpanther9229] #4

nus-se-script opened this issue Sep 14, 2024 · 0 comments

Comments

@nus-se-script
Copy link

@blackpanther9229 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/nah/parser/Parser.java lines 42-179:

    public static Command parse(String fullCommand) throws NahException {
        assert fullCommand != null : "fullCommand cannot be null";
        String[] cmd = fullCommand.split(" ", 2);
        assert cmd[0] != null : "unexpected null value for command";

        switch (cmd[0].toLowerCase()) {
        case "bye": {
            return new Command.ExitCommand();
        }
        case "clean": {
            if (cmd.length >= 2 && !cmd[1].trim().isEmpty()) {
                throw new NahException(" Nahh!!! Do not type nonsense after 'clean' command\n");
            }
            return new Command.CleanCommand();
        }
        case "list": {
            if (cmd.length >= 2 && !cmd[1].trim().isEmpty()) {
                throw new NahException(" Nahh!!! Do not type nonsense after 'list' command\n");
            }
            return new Command.ListCommand();
        }
        case "find": {
            if (cmd.length < 2) {
                return new Command.FindCommand("");
            }
            return new Command.FindCommand(cmd[1]);
        }
        case "mark": {
            if (cmd.length < 2) {
                throw new NahException(
                        " Nah!!! Mark command needs a number\n");
            }
            int i;
            try {
                i = parseInt(cmd[1]);
            } catch (NumberFormatException e) {
                throw new NahException(
                        " Nah.Nah!!! Please give me a valid ordinal number for the task\n");
            }
            return new Command.MarkCommand(i);
        }
        case "help" : {
            return new Command.HelpCommand();
        }
        case "unmark": {
            if (cmd.length < 2) {
                throw new NahException(
                        " Nah!!! Unmark command needs a number\n");
            }
            int i;
            try {
                i = parseInt(cmd[1]);
            } catch (NumberFormatException e) {
                throw new NahException(
                        " Nah.Nah!!! Please give me a valid ordinal number for the task\n");
            }
            return new Command.UnmarkCommand(i);
        }
        case "delete": {
            if (cmd.length < 2) {
                throw new NahException(
                        " Nah!!! Delete command needs a number\n");
            }
            int i;
            try {
                i = parseInt(cmd[1]);
            } catch (NumberFormatException e) {
                throw new NahException(
                        " Nah.Nah!!! Please give me a valid ordinal number for the task\n");
            }
            return new Command.DeleteCommand(i);
        }
        case "dueon": {
            if (cmd.length < 2) {
                throw new NahException(
                        " Nah!!! DueOn command needs a number\n");
            }
            return new Command.DueOnCommand(cmd[1]);
        }
        case "todo": {
            if (cmd.length < 2 || cmd[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhh!!! Todo needs description\n");
            }
            return new Command.AddCommand(new Task.ToDos(cmd[1].trim()));
        }
        case "deadline": {
            if (cmd.length < 2 || cmd[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhh!!! Deadline needs description\n");
            }
            String[] des = cmd[1].split("/by", 2);
            if (des.length < 2 || des[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhhhhhh!!! Deadline needs deadline\n");
            }
            LocalDateTime by;
            try {
                by = LocalDateTime.parse(des[1].trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
            } catch (DateTimeParseException e) {
                throw new NahException(
                        " Nahh!!! Time should be in the format yyyy-mm-dd hhmm, with valid date and time\n");
            }
            return new Command.AddCommand(new Task.Deadlines(des[0].trim(), by));
        }
        case "event": {
            if (cmd.length < 2 || cmd[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhh!!! Event needs description\n");
            }
            String[] des = cmd[1].split("/from", 2);
            if (des.length < 2 || des[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhhhhhh!!! Event needs starting time\n");
            }
            String[] time = des[1].split("/to", 2);
            if (time.length < 2 || time[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhhhhhhhhh!!! Event needs ending time\n");
            }
            LocalDateTime start;
            LocalDateTime end;
            try {
                start = LocalDateTime.parse(time[0].trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
                end = LocalDateTime.parse(time[1].trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
            } catch (DateTimeParseException e) {
                throw new NahException(
                        " Nahh!!! Time should be in the format yyyy-mm-dd hhmm, with valid date and time\n");
            }

            return new Command.AddCommand(new Task.Events(des[0].trim(), start, end));
        }
        default: {
            return new Command.UnknownCommand();
        }
        }

    }

Example from src/main/java/nah/storage/Decoder.java lines 34-96:

    public static Task decode(String s) throws NahException {
        if (!checkFirstThreeComponent(s)) {
            throw new NahException.InvalidFileValueException();
        }
        String[] command = s.split("\\|", 3);
        if (command[0].trim().equals("T")) {

            assert command[0].trim().equals("T") : "the command symbol should be T";
            Task t = new Task.ToDos(command[2].trim());
            if (command[1].trim().equals("1")) {
                t.mark();
            }
            return t;
        }
        if (command[0].trim().equals("D")) {

            assert command[0].trim().equals("D") : "the command symbol should be D";
            String[] des = command[2].split("\\|", 2);
            if (des.length < 2 || des[1].trim().isEmpty()) {
                throw new NahException.InvalidFileValueException();
            }
            try {
                LocalDateTime time = LocalDateTime
                        .parse(des[1].trim(), DateTimeFormatter.ofPattern("MMM d yyyy, h:mm a"));
                Task t = new Task.Deadlines(des[0].trim(), time);
                if (command[1].trim().equals("1")) {
                    t.mark();
                }
                return t;
            } catch (DateTimeParseException e) {
                throw new NahException.InvalidFileValueException();
            }

        }

        if (command[0].trim().equals("E")) {

            assert command[0].trim().equals("E") : "the command symbol should be E";
            String[] des = command[2].split("\\|", 2);
            if (des.length < 2 || des[1].trim().isEmpty()) {
                throw new NahException.InvalidFileValueException();
            }
            String[] time = des[1].split("\\|", 2);
            if (time.length < 2 || time[1].trim().isEmpty()) {
                throw new NahException.InvalidFileValueException();
            }
            try {
                LocalDateTime start = LocalDateTime
                        .parse(time[0].trim(), DateTimeFormatter.ofPattern("MMM d yyyy, h:mm a"));
                LocalDateTime end = LocalDateTime
                        .parse(time[1].trim(), DateTimeFormatter.ofPattern("MMM d yyyy, h:mm a"));
                assert start.isBefore(end) : "Start time must be before End time";
                Task t = new Task.Events(des[0].trim(), start, end);
                if (command[1].trim().equals("1")) {
                    t.mark();
                }
                return t;
            } catch (DateTimeParseException e) {
                throw new NahException.InvalidFileValueException();
            }
        }
        throw new NahException.InvalidFileValueException();
    }

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/nah/DialogBox.java lines 85-90:

    /**
     * return a DialogBox for user.
     * @param text corresponding text
     * @param img avatar for user
     * @return a DialogBox
     */

Example from src/main/java/nah/DialogBox.java lines 95-100:

    /**
     * return a DialogBox for chatBot Nah.
     * @param text corresponding text
     * @param img avatar for Nah
     * @return a DialogBox
     */

Example from src/main/java/nah/storage/Storage.java lines 48-53:

    /**
     * Return a LinkList of tasks extracted from the file at filePath (helper method).
     *
     * @return a LinkList object
     * @throws NahException if something wrong with the filePath
     */

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

possible problems in commit b71badb:


Make Nah chatBot more user friendly by opening a new
Help Window when taking certain input

To do this, let's,
* Create a new class HelpWindow extends Anchorpane
* Create a class HelpWindowResponse to handle input from
HelpWindow


  • No blank line between subject and body

Suggestion: Follow the given conventions for Git commit messages for future commits (do not modify past commit messages as doing so will change the commit timestamp that we used to detect your commit timings).

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant