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 @lennoxtr] #1

Open
soc-se-bot-blue opened this issue Feb 11, 2023 · 0 comments
Open

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

soc-se-bot-blue opened this issue Feb 11, 2023 · 0 comments

Comments

@soc-se-bot-blue
Copy link

@lennoxtr 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/duke/workflow/DoTask.java lines 27-27:

    private boolean firstGreet;

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/duke/io/input/exception/UserInputException.java lines 27-97:

    public static void checkUserInput(String input, int currentSize) throws DukeException {
        String[] inputSplitArray = input.split(" ");
        List<String> inputSplitList = Arrays.asList(inputSplitArray);
        String command = inputSplitList.get(0);
        if (command.equals("TODO")) {
            if (inputSplitList.size() <= 1) {
                throw new DukeException("EMPTY TO-DO COMMAND... DOING NOTHING MUCH?");
            }
        } else if (command.equals("DEADLINE")) {
            if (input.contains(" /BY ")) {
                if (inputSplitList.size() <= 3) {
                    throw new DukeException("MORE INFO NEEDED FOR DEADLINE");
                }
            } else {
                throw new DukeException("NO DEADLINE. FREE TIME ISN'T SO EASY TO COME BY.");
            }
        } else if (command.equals("EVENT")) {
            if (input.contains(" /FROM ") && input.contains(" /TO ")) {
                if (inputSplitList.size() <= 5) {
                    throw new DukeException("MORE INFO NEEDED FOR EVENT");
                }
            } else {
                throw new DukeException("MY CREATOR DIDN'T MAKE ME SMART ENOUGH TO INFER INFO FROM THIS...");
            }
        } else if (command.equals("MARK")) {
            if (inputSplitList.size() == 1) {
                throw new DukeException("MY CREATOR DIDN'T MAKE ME SMART ENOUGH TO INFER INFO FROM THIS...");
            }
            if (inputSplitList.size() > 2) {
                throw new DukeException("TOO MUCH INFO...");
            } else {
                if (Integer.valueOf(inputSplitList.get(1)) > currentSize) {
                    if (currentSize > 1) {
                        throw new DukeException("YOU ONLY HAVE " + currentSize + " TASKS");
                    } else {
                        throw new DukeException("YOU ONLY HAVE " + currentSize + " TASK");
                    }
                }
            }

        } else if (command.equals("UNMARK")) {
            if (inputSplitList.size() == 1) {
                throw new DukeException("MY CREATOR DIDN'T MAKE ME SMART ENOUGH TO INFER INFO FROM THIS...");
            }
            if (inputSplitList.size() > 2) {
                throw new DukeException("TOO MUCH INFO...");
            } else {
                if (Integer.valueOf(inputSplitList.get(1)) > currentSize) {
                    throw new DukeException("YOU DON'T HAVE THAT MANY TASKS");
                }
            }

        } else if (command.equals("DELETE")) {
            if (inputSplitList.size() > 2) {
                throw new DukeException("TOO MUCH INFO...");
            } else {
                if (Integer.valueOf(inputSplitList.get(1)) > currentSize) {
                    throw new DukeException("YOU DON'T HAVE THAT MANY TASKS");
                }
            }

        } else if (command.equals("LIST")) {
            if (inputSplitList.size() > 1) {
                throw new DukeException("ARE YOU EXPECTING ME TO DO SOMETHING WITH THE EXTRA INFO?");
            }
        } else if (command.equals("FIND")) {

        } else {
            throw new DukeException("COMMAND NOT FOUND... WHAT ARE YOU UP TO...");
        }
    }

Example from src/main/java/duke/io/input/ui/UserInteraction.java lines 73-115:

    public void chatBegin() {
        Scanner sc = new Scanner(System.in);
        Greeting greeting = new Greeting();
        UserInteraction.printWithBracket(greeting.toString());
        String isPlaying = sc.nextLine();
        if (isPlaying.equals("NO")) {
            greeting = new Greeting(0);
            Event nextEvent = greeting.toNext();
            UserInteraction.printWithBracket(nextEvent.toString());
        } else if (isPlaying.equals("YES")) {
            greeting = new Greeting(1);
            Event nextEvent = greeting.toNext();
            UserInteraction.printWithBracket(nextEvent.toString());
            while (nextEvent.getStatus() == false) {
                nextEvent = nextEvent.toNext();
                UserInteraction.printWithBracket(nextEvent.toString());
            }
            System.out.println("SAVE YOUR GRAND PLAN FOR ANOTHER DAY? ");
            String isSaving = sc.nextLine();
            if (isSaving.equals("YES")) {
                Storage.saveProgress(nextEvent.getTaskList());
            }
        } else {
            while (!isPlaying.equals("YES") && !isPlaying.equals("NO")) {
                UserInteraction.printWithBracket("FOCUS, HUMAN. "
                        + "YOU ARE TO ENTER INPUT WITH FULL CAPS.");
                isPlaying = sc.nextLine();
            }
            if (isPlaying.equals("NO")) {
                greeting = new Greeting(0);
                Event end = greeting.toNext();
                UserInteraction.printWithBracket(end.toString());
            } else {
                greeting = new Greeting(1);
                Event nextEvent = greeting.toNext();
                UserInteraction.printWithBracket(nextEvent.toString());
                while (nextEvent.getStatus() == false) {
                    nextEvent = nextEvent.toNext();
                    UserInteraction.printWithBracket(nextEvent.toString());
                }
            }
        }
    }

Example from src/main/java/duke/workflow/DoTask.java lines 53-163:

    public Event toNext() {
        Scanner sc = new Scanner(System.in);
        String nextTask = sc.nextLine();
        if (nextTask.equals("BYE")) {
            return new Ending(this.taskList);
        } else {
            try {
                UserInputException.checkUserInput(nextTask, this.taskList.getSize());
                if (nextTask.equals("LIST")) {
                    this.firstGreet = false;
                    this.lastCommand = nextTask;
                    return this;
                } else {
                    String[] command = nextTask.split(" ");
                    List<String> words = Arrays.asList(command);
                    if (words.get(0).equals("MARK")) {
                        this.firstGreet = false;
                        this.lastCommand = nextTask;
                        this.taskList = this.taskList.markDone(Integer.valueOf(words.get(1)) - 1);
                        return this;
                    }
                    if (words.get(0).equals("UNMARK")) {
                        this.firstGreet = false;
                        this.lastCommand = nextTask;
                        this.taskList = this.taskList.unMark(Integer.valueOf(words.get(1)) - 1);
                        return this;
                    }
                    if (words.get(0).equals("TODO")) {
                        String[] toDoTask = nextTask.split("TODO ");
                        List<String> toDoAction = Arrays.asList(toDoTask);
                        this.firstGreet = false;
                        this.lastCommand = toDoAction.get(1);
                        ToDo newTask = new ToDo(toDoAction.get(1));
                        this.taskList = this.taskList.addTask(newTask);
                        for (String i : words) {
                            this.storage = this.storage.addToStorage(i, newTask);
                        }
                        return this;
                    }
                    if (words.get(0).equals("DEADLINE")) {
                        String[] toDoTask = nextTask.split(" /BY ");
                        List<String> deadlineList = Arrays.asList(toDoTask);
                        String deadlineAction = deadlineList.get(0);
                        String[] deadlinePhraseArray = deadlineAction.split("DEADLINE ");
                        List<String> deadlinePhraseList = Arrays.asList(deadlinePhraseArray);
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm");
                        Deadline newTask = new Deadline(
                                LocalDateTime.parse(deadlineList.get(1), format),
                                deadlinePhraseList.get(1));
                        for (String i : words) {
                            this.storage = this.storage.addToStorage(i, newTask);
                        }
                        this.firstGreet = false;
                        this.lastCommand = deadlinePhraseList.get(1);
                        this.taskList = this.taskList.addTask(newTask);
                        return this;
                    }
                    if (words.get(0).equals("EVENT")) {
                        String[] splitFrom = nextTask.split(" /FROM ");
                        List<String> eventActionSplit = Arrays.asList(splitFrom);
                        String timeLinePhrase = eventActionSplit.get(1);
                        String eventAction = eventActionSplit.get(0);
                        String[] eventPhraseArray = eventAction.split("EVENT ");
                        List<String> eventPhraseList = Arrays.asList(eventPhraseArray);
                        String[] timeFrame = timeLinePhrase.split(" /TO ");
                        List<String> timeLineSplit = Arrays.asList(timeFrame);
                        String eventBegin = timeLineSplit.get(0);
                        String eventEnd = timeLineSplit.get(1);
                        DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HHmm");
                        ScheduledEvent newTask = new ScheduledEvent(
                                LocalDateTime.parse(eventBegin, format),
                                LocalDateTime.parse(eventEnd, format),
                                eventPhraseList.get(1));
                        for (String i : words) {
                            this.storage = this.storage.addToStorage(i, newTask);
                        }
                        this.firstGreet = false;
                        this.lastCommand = eventPhraseList.get(1);
                        this.taskList = this.taskList.addTask(newTask);
                        return this;
                    }
                    if (words.get(0).equals("DELETE")) {
                        this.firstGreet = false;
                        this.removedTask = this.taskList.getTask(Integer.valueOf(words.get(1)) - 1);
                        String[] splitRemovedTask = this.removedTask.toString().split(" ");
                        List<String> removedTaskArray = Arrays.asList(splitRemovedTask);
                        for (String i : removedTaskArray) {
                            this.storage = this.storage.removeFromStorage(i, this.removedTask);
                        }
                        this.lastCommand = nextTask;
                        this.taskList = this.taskList.removeTask(Integer.valueOf(words.get(1)) - 1);
                        return this;
                    }
                    if (words.get(0).equals("FIND")) {
                        String[] toFind = nextTask.split("FIND ");
                        List<String> keywords = Arrays.asList(toFind);
                        TaskList findList = this.storage.getTaskList(keywords.get(1));
                        this.firstGreet = false;
                        this.foundList = findList;
                        this.lastCommand = nextTask;
                        return this;
                    }
                }
            } catch (DukeException exception) {
                System.out.println(exception);
            } catch (Exception exception) {
                System.out.println("ERRRR ERROR ERRR. SYSTEM FAILURE. UNKNOWN EXCEPTION. ERR ERR");
            }
        }
        return this;
    }

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/duke/Duke.java lines 6-10:

    /**
     * Initialize Duke chatbot and begin chatting with user.
     *
     * @param args
     */

Example from src/main/java/duke/io/input/ui/UserInteraction.java lines 26-28:

    /**
     * Print out Duke's logo.
     */

Example from src/main/java/duke/util/Storage.java lines 22-25:

    /**
     * Construct the {@code Storage} object with
     * empty database
     */

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)

possible problems in commit c8b487f:

Fixed Codestyle

  • Not in imperative mood (?)

possible problems in commit 714e4cd:

Merge remote-tracking branch 'origin/add-gradle-support' into branch-Level-7

  • Longer than 72 characters

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

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