Skip to content

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

@soc-se-bot-blue

Description

@soc-se-bot-blue

@iapetusbob 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

Example from src/main/java/DukeHelpfulCode/Commands/AddCommand.java lines 1-1:

package DukeHelpfulCode.Commands;

Example from src/main/java/DukeHelpfulCode/Commands/Command.java lines 1-1:

package DukeHelpfulCode.Commands;

Example from src/main/java/DukeHelpfulCode/Commands/DeleteCommand.java lines 1-1:

package DukeHelpfulCode.Commands;

Suggestion: Follow the package naming convention specified by the coding standard.

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/DukeHelpfulCode/Utilities/Parser.java lines 16-152:

    public static Command parse(String fullCommand) throws NoTaskTypeException, NoTaskNameException, NoDueTimeException, NoStartTimeException, NoEndTimeException, NoSuchTaskException {
        Command cmd = new HelpCommand();
        String[] cmdArr = fullCommand.split(" ");

        if (cmdArr.length == 1 && cmdArr[0].equals("bye")){
            cmd = new ExitCommand();
            return cmd;

        } else if (cmdArr.length == 1 && cmdArr[0].equals("help")){
            cmd = new HelpCommand();
            return cmd;
        } else if (cmdArr.length == 1 && cmdArr[0].equals("list")){
            cmd = new ListCommand();
            return cmd;
        }

        // check for task type, task name, start end due datetime
        // input will be in the form of:
        // >bye
        // >help
        // >add event name /from sdt /to edt
        // >mark 1 -> first item so 0th index
        // >unmark 1 -> first item so 0th index
        // >delete 1 -> first item to 0th index

        if (cmdArr[0].equals("add")){
            String[] taskTypes = {"todo", "event", "deadline"};
            String taskName = "";
            Task task;
            // no task name
            // if deadline -> no due time
            // if event -> no sdt or no edt


            if (cmdArr.length == 1){
                throw new NoTaskTypeException();
            } else if (cmdArr.length == 2){
                if (!Arrays.asList(taskTypes).contains(cmdArr[1])){
                    throw new NoTaskTypeException();
                } else {
                    throw new NoTaskNameException();
                }


            } else {
                if (cmdArr[1].equals("todo")){
                    for (int i = 2; i < cmdArr.length; i++){
                        taskName += cmdArr[i];
                    }
                    task = new Todo(taskName);


                } else if (cmdArr[1].equals("deadline")) {
                    // >add deadline name /by dueDate
                    if (!Arrays.asList(cmdArr).contains("/by")) {
                        throw new NoDueTimeException();
                    } else if(cmdArr[2].equals("/by")){
                        throw new NoTaskNameException();
                    } else {
                        int by = Arrays.asList(cmdArr).indexOf("/by");
                        for (int i = 2; i < by; i++) {
                            taskName += cmdArr[i];
                        }
                        String dt = "";
                        for (int i = by + 1; i < cmdArr.length; i++){
                            dt += cmdArr[i] + " ";
                        }
                        task = new Deadline(taskName,dt.substring(0,dt.length()-1));
                    }


                } else if (cmdArr[1].equals("event")){
                    // >add event name /from sdt /to edt
                    if (!Arrays.asList(cmdArr).contains("/from")) {
                        throw new NoStartTimeException();
                    } else if(!Arrays.asList(cmdArr).contains("/to")){
                        throw new NoEndTimeException();
                    } else if(cmdArr[2].equals("/from")){
                        throw new NoTaskNameException();
                    } else {
                        int start = Arrays.asList(cmdArr).indexOf("/from");
                        int end = Arrays.asList(cmdArr).indexOf("/to");
                        for (int i = 2; i < start; i++) {
                            taskName += cmdArr[i];
                        }
                        String sdt = "";
                        for (int i = start + 1; i < end; i++){
                            sdt += cmdArr[i] + " ";
                        }
                        String edt = "";
                        for (int i = end + 1; i < cmdArr.length; i++){
                            edt += cmdArr[i];
                        }
                        task = new Event(taskName, sdt.substring(0,sdt.length()-1), edt.substring(0,edt.length()-1));
                    }
                } else {
                    throw new NoTaskTypeException();
                }
            }
            cmd = new AddCommand(task);


        } else if (cmdArr[0].equals("delete")){
            int taskNum;
            try {
                taskNum = Integer.parseInt(cmdArr[1]);
            } catch (NumberFormatException e) {
                throw new NoSuchTaskException();
            }
            cmd = new DeleteCommand(taskNum);


        } else if (cmdArr[0].equals("mark")){
            boolean isMark = true;
            int taskNum;
            try {
                taskNum = Integer.parseInt(cmdArr[1]);
            } catch (NumberFormatException e) {
                throw new NoSuchTaskException();
            }
            cmd = new MarkCommand(isMark, taskNum);
        } else if (cmdArr[0].equals("unmark")){
            boolean isMark = false;
            int taskNum;
            try {
                taskNum = Integer.parseInt(cmdArr[1]);
            } catch (NumberFormatException e) {
                throw new NoSuchTaskException();
            }
            cmd = new MarkCommand(isMark, taskNum);
            // mark command in tasklist need to change from unmark and mark to this boolean

        } else {
            System.out.println("Sorry, I don't understand.\nBut don't worry, help is here!\n");
        }
        return cmd;
    }

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 Message (Subject Only)

possible problems in commit 871d399:

JAR

  • Perhaps too short (?)

possible problems in commit b6de93c:

MoreOOP

  • Perhaps too short (?)

possible problems in commit dff68ac:

Level-8

  • Perhaps too short (?)

Suggestion: Follow the given conventions for Git commit messages for future commits (no need to modify past commit messages).

Aspect: Binary files in repo

Suggestion: Avoid committing binary files (e.g., *.class, *.jar, *.exe) or third-party library files in to the repo.

ℹ️ 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