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 @yashpola] - Round 2 #5

Open
soc-se-bot opened this issue Mar 19, 2024 · 0 comments
Open

Sharing iP code quality feedback [for @yashpola] - Round 2 #5

soc-se-bot opened this issue Mar 19, 2024 · 0 comments

Comments

@soc-se-bot
Copy link

@yashpola We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).

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/main/java/nicole/gui/DialogBox.java lines 42-42:

//        displayPicture.setImage(img);

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/nicole/task/Event.java lines 34-91:

    private void parseDateTime(String name) throws NicoleException {
        /*
         The expected structure of this array is [..., from, date, at, time, to, date, at, time] where the
         ... are the event description words
         */
        String[] whiteSpaceSeparatedDate = name.split(" ");

        StringBuilder eventDescription = new StringBuilder();
        for (int i = 0; i < whiteSpaceSeparatedDate.length - 8; i++) {
            eventDescription.append(whiteSpaceSeparatedDate[i]).append(" ");
        }
        super.updateName(eventDescription.toString());

        try {
            for (int i = 0; i < whiteSpaceSeparatedDate.length; i++) {
                if (whiteSpaceSeparatedDate[i].matches("\\d{4}-\\d{2}-\\d{2}")
                    && i < whiteSpaceSeparatedDate.length - 4) {
                    deadlineFromDateTimeLocalDate = LocalDateTime.parse(whiteSpaceSeparatedDate[i]
                            + "T" + whiteSpaceSeparatedDate[i + 2]);
                } else if (whiteSpaceSeparatedDate[i].matches("\\d{4}-\\d{2}-\\d{2}")
                           && i > whiteSpaceSeparatedDate.length - 4) {
                    deadlineToDateTimeLocalDate = LocalDateTime.parse(whiteSpaceSeparatedDate[i]
                            + "T" + whiteSpaceSeparatedDate[i + 2]);
                } else {
                    eventDescription.append(whiteSpaceSeparatedDate[i]).append(" ");
                }
            }
        } catch (DateTimeParseException e) {
            throw new NicoleException("Are you sure your date and time are in the proper "
                                      + "[YYYY-MM-DD] and [HH-MM-SS] format...?");
        }
        if (deadlineFromDateTimeLocalDate.isAfter(deadlineToDateTimeLocalDate)) {
            throw new NicoleException("Erm, the 'to' datetime can't be before 'from' right...");
        }

        if (deadlineFromDateTimeLocalDate.isBefore(LocalDateTime.now())
            || deadlineToDateTimeLocalDate.isBefore(LocalDateTime.now())) {
            throw new NicoleException("Erm, the event can't before now right...");
        }

        deadlineFromDateReformattedString = ""
                + deadlineFromDateTimeLocalDate.getDayOfMonth() + " "
                + deadlineFromDateTimeLocalDate.getMonth().toString() + " "
                + deadlineFromDateTimeLocalDate.getYear();
        deadlineToDateReformattedString = ""
                + deadlineToDateTimeLocalDate.getDayOfMonth() + " "
                + deadlineToDateTimeLocalDate.getMonth().toString() + " "
                + deadlineToDateTimeLocalDate.getYear();
        deadlineFromTimeReformattedString = ""
                + deadlineFromDateTimeLocalDate.getHour() + " "
                + deadlineFromDateTimeLocalDate.getMinute() + " "
                + deadlineFromDateTimeLocalDate.getSecond();
        deadlineToTimeReformattedString = ""
                + deadlineToDateTimeLocalDate.getHour() + " "
                + deadlineToDateTimeLocalDate.getMinute() + " "
                + deadlineToDateTimeLocalDate.getSecond();

    }

Example from src/main/java/nicole/userrequests/Request.java lines 40-99:

    public String handleRequest(String request) throws NicoleException {
        TaskList taskList = new TaskList();
        if (request.contains("unmark")) {
            try {
                int taskNumber = Integer.parseInt(request.substring(7));
                return taskList.unmarkTask(taskNumber);
            } catch (StringIndexOutOfBoundsException | NumberFormatException e) {
                throw new NicoleException("unmark [task number] pls...");
            }
        } else if (request.contains("mark")) {
            try {
                int taskNumber = Integer.parseInt(request.substring(5));
                return taskList.markTask(taskNumber);
            } catch (StringIndexOutOfBoundsException | NumberFormatException e) {
                throw new NicoleException("mark [task number] pls...");
            }
        } else if (request.contains("delete")) {
            try {
                int taskNumber = Integer.parseInt(request.substring(7));
                return taskList.deleteTask(taskNumber);
            } catch (StringIndexOutOfBoundsException | NumberFormatException e) {
                throw new NicoleException("delete [task number] pls...");
            }
        } else if (request.equals("help")) {
            return "I'm your task/deadline/event manager! I'm down with these requests,\n"
                    + "1. todo [task]\n"
                    + "2. deadline [task] by YYYY-MM-DD\n"
                    + "3. event [description] from YYYY-MM-DD at HH:MM:SS to YYYY-MM-DD at HH:MM:SS\n"
                    + "4. list\n"
                    + "5. mark [tasknumber]\n"
                    + "6. unmark [tasknumber]\n"
                    + "7. delete [tasknumber]\n"
                    + "8. sort by date\n"
                    + "9. find [keyword]\n"
                    + "10. update [tasknumber] [new task name]\n"
                    + "11. bye\n"
                    + "12. help";
        } else if (request.equals("sort by date")) {
            return taskList.sortTasksByDate();
        } else if (request.contains("find")) {
            try {
                String taskKeyWord = request.substring(6);
                return taskList.findTasks(taskKeyWord);
            } catch (StringIndexOutOfBoundsException | NumberFormatException e) {
                throw new NicoleException("find [keyword] pls...");
            }
        } else if (request.contains("update")) {
            try {
                int taskNumber = Integer.parseInt(request.substring(7, 8));
                String newTaskName = request.substring(9);
                return taskList.updateTask(newTaskName, taskNumber);
            } catch (StringIndexOutOfBoundsException | NumberFormatException e) {
                throw new NicoleException("update [task number] [name] pls...");
            }
        } else if (!request.equals("list")) {
            return taskList.addTask(newTask);
        } else {
            return taskList.listTasks();
        }
    }

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/nicole/userrequests/Ui.java lines 28-32:

    /**
     * Dynamically Greets the user with the current date and appropriate salutation.
     *
     * @return a greeting.
     */

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

No easy-to-detect issues 👍

Aspect: Binary files in repo

No easy-to-detect issues 👍


❗ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality 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