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

Open
nus-se-bot opened this issue Sep 16, 2023 · 0 comments
Open

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

nus-se-bot opened this issue Sep 16, 2023 · 0 comments

Comments

@nus-se-bot
Copy link

@johnnythesnake12 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/duke/Duke.java lines 25-155:

    public void run() {
        ui.showWelcomeMessage();

        while (true) {
            String userInput = ui.getUserInput();
            Command command = Parser.parseCommand(userInput);
            String description = Parser.parseDescription(userInput);
            switch (command) {
                case EXIT:
                    storage.save(tasks, "tasks.txt");
                    ui.closeScanner();
                    ui.showExitMessage();
                    return;
                case LIST:
                    ui.showTaskList(tasks);
                    break;
                case UNMARK:
                    try {
                        int taskNumber = Integer.parseInt(description) - 1;
                        if (taskNumber >= 0 && taskNumber < tasks.size()) {
                            tasks.unmarkTask(taskNumber);
                        } else {
                            ui.showError("Task number out of range.");
                        }
                    } catch (NumberFormatException e) {
                        ui.showError("Invalid task number. Please provide a valid integer.");
                    }
                    break;
                case MARK:
                    try {
                        int taskNumber = Integer.parseInt(description) - 1;
                        if (taskNumber >= 0 && taskNumber < tasks.size()) {
                            tasks.markTaskAsDone(taskNumber);
                        } else {
                            ui.showError("Task number out of range.");
                        }
                    } catch (NumberFormatException e) {
                        ui.showError("Invalid task number. Please provide a valid integer.");
                    }
                    break;
                case TODO:
                    try {
                        if (description.isEmpty()) {
                            throw new EmptyTodoException();
                        }
                        Todo todo = new Todo(description, false);
                        tasks.addTask(todo);

                    } catch (EmptyTodoException e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                case DEADLINE:

                    if (description.isEmpty()) {
                        try {
                            throw new EmptyDeadlineException();
                        } catch (EmptyDeadlineException e) {
                            System.out.println(e.getMessage());
                        }
                    } else {
                        // Find the index of the deadline separator "/"
                        int separatorIndex = description.indexOf('/');

                        if (separatorIndex != -1) { // Ensure the separator exists in the input
                            // Extract the task description and deadline

                            String descriptionString = description.substring(0, separatorIndex).trim();
                            String deadline = description.substring(separatorIndex + 4).trim();
                            String pattern = "\\d{4}/\\d{2}/\\d{2}";
                            Pattern datePattern = Pattern.compile(pattern);
                            Matcher matcher = datePattern.matcher(deadline);
                            if (matcher.find()) {
                                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
                                LocalDate localDateDeadline = LocalDate.parse(deadline, formatter);
                                Deadline deadlineTask = new Deadline(descriptionString, false, localDateDeadline);
                                tasks.addTask(deadlineTask);

                            } else {
                                System.out.println("Please input your deadline in YYYY/MM/DD format");
                            }
                        } else {
                            System.out.println("Invalid input format for deadline. Please input in the following format: <deadline> <description> /by <YYYY/MM/DD> ");
                        }
                    }
                    break;
                case EVENT:
                    if (description.isEmpty()) {
                        try {
                            throw new EmptyEventException();
                        } catch (EmptyEventException e) {
                            System.out.println(e.getMessage());
                        }
                    } else {
                        // Find the indices of the time separators
                        int fromIndex = description.indexOf("/from");
                        int toIndex = description.indexOf("/to");

                        if (fromIndex != -1 && toIndex != -1) {
                            // Extract the task description, startTime, and endTime
                            String descriptionString = description.substring(0, fromIndex).trim();
                            String startTime = description.substring(fromIndex + 5, toIndex).trim();
                            String endTime = description.substring(toIndex + 3).trim();

                            // Create a new Event object
                            Event eventTask = new Event(descriptionString, false, startTime, endTime);
                            tasks.addTask(eventTask);

                        } else {
                            System.out.println("Invalid input format for event command.");
                        }
                    }
                    break;
                case DELETE:
                    try {
                        int taskNumber = Integer.parseInt(description) - 1;
                        if (taskNumber >= 0 && taskNumber < tasks.size()) {
                            tasks.deleteTask(taskNumber);
                        } else {
                            ui.showError("Task number out of range.");
                        }
                    } catch (NumberFormatException e) {
                        ui.showError("Invalid task number. Please provide a valid integer.");
                    }
                    break;
                case INVALID:
                    ui.showError("Invalid command. Please try again.");
                    break;
            }
        }
    }

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

possible problems in commit 7f86037:


Packaged all into duke


  • Not in imperative mood (?)

possible problems in commit 96f087e:


Added UI,Parser, Storage and TaskList


  • Not in imperative mood (?)

possible problems in commit f56c1a7:


Cleaned up modularity of files


  • Not in imperative mood (?)

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 cs2103@comp.nus.edu.sg 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