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 @xplus2g4] #4

Open
soc-se-bot-red opened this issue Feb 15, 2025 · 0 comments
Open

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

soc-se-bot-red opened this issue Feb 15, 2025 · 0 comments

Comments

@soc-se-bot-red
Copy link

@xplus2g4 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/olivia/Olivia.java lines 51-167:

    public void start(Stage primaryStage) {
        ComboBox<String> taskType = new ComboBox<>();
        TaskPicker taskPicker = new TaskPicker();

        taskType.getItems().addAll("Todo", "Deadline", "Event");
        taskType.setValue("Todo");
        taskPicker.setTasks(taskList.getTasks());

        TextField taskInput = new TextField();
        DatePicker deadlinePicker = new DatePicker();
        DatePicker eventStartPicker = new DatePicker();
        DatePicker eventEndPicker = new DatePicker();

        Button addButton = new Button("Add");
        Button deleteButton = new Button("Delete");
        Button markDoneButton = new Button("Mark Done");
        Button markUndoneButton = new Button("Mark Undone");
        Button byeButton = new Button("Bye");

        // Layout
        VBox inputFields = new VBox(10, taskPicker.getTaskPicker(), taskInput);
        HBox inputBox = new HBox(10, taskType, inputFields, addButton);
        HBox buttonBox = new HBox(10, markDoneButton, markUndoneButton, deleteButton, byeButton);
        VBox layout = new VBox(10, taskList.getTasksView(), inputBox, buttonBox);
        layout.setStyle("-fx-padding: 20; -fx-alignment: center;");

        // Event Handlers
        taskType.setOnAction(e -> {
            inputFields.getChildren().clear();
            inputFields.getChildren().addAll(taskInput, taskPicker.getTaskPicker());
            if (taskType.getValue().equals("Deadline")) {
                inputFields.getChildren().add(deadlinePicker);
            } else if (taskType.getValue().equals("Event")) {
                inputFields.getChildren().addAll(eventStartPicker, eventEndPicker);
            }
        });

        addButton.setOnAction(e -> {
            String taskDescription = taskInput.getText().trim();
            if (!taskDescription.isEmpty()) {
                Optional<TaskBuilder> taskBuilder = Optional.empty();
                if (taskType.getValue().equals("Todo")) {
                    TodoBuilder builder = new TodoBuilder(taskDescription);
                    taskBuilder = Optional.of(builder);
                } else if (taskType.getValue().equals("Deadline")) {
                    LocalDate deadline = deadlinePicker.getValue();
                    if (deadline == null) {
                        return;
                    }

                    DeadlineBuilder builder = new DeadlineBuilder(taskDescription, deadline.atStartOfDay());
                    taskBuilder = Optional.of(builder);
                } else if (taskType.getValue().equals("Event")) {
                    LocalDate start = eventStartPicker.getValue();
                    LocalDate end = eventEndPicker.getValue();
                    if (start == null || end == null) {
                        return;
                    }

                    EventBuilder builder = new EventBuilder(taskDescription, start.atStartOfDay(), end.atStartOfDay());
                    taskBuilder = Optional.of(builder);
                }

                if (taskBuilder.isPresent()) {
                    Optional<Task> previousTask = taskPicker.getTaskPicker().getValue();
                    Task task = taskBuilder.get().withPreviousTask(previousTask).build();
                    AddCommand addCommand = new AddCommand(task);

                    addCommand.execute(taskList, storage);
                    taskPicker.setTasks(taskList.getTasks());
                    taskInput.clear();
                    deadlinePicker.setValue(null);
                    eventStartPicker.setValue(null);
                    eventEndPicker.setValue(null);
                }
            }
        });

        deleteButton.setOnAction(e -> {
            int selectedIndex = taskList.getTasksView().getSelectionModel().getSelectedIndex();
            if (selectedIndex >= 0) {
                Task task = taskList.getTaskInView(selectedIndex);
                DeleteCommand deleteCommand = new DeleteCommand(task);
                deleteCommand.execute(taskList, storage);
            }
        });

        markDoneButton.setOnAction(e -> {
            int selectedIndex = taskList.getTasksView().getSelectionModel().getSelectedIndex();
            if (selectedIndex >= 0) {
                Task task = taskList.getTaskInView(selectedIndex);
                MarkCommand markCommand = new MarkCommand(task);
                markCommand.execute(taskList, storage);
            }
        });

        markUndoneButton.setOnAction(e -> {
            int selectedIndex = taskList.getTasksView().getSelectionModel().getSelectedIndex();
            if (selectedIndex >= 0) {
                Task task = taskList.getTaskInView(selectedIndex);
                UnmarkCommand unmarkCommand = new UnmarkCommand(task);
                unmarkCommand.execute(taskList, storage);
            }
        });

        byeButton.setOnAction(e -> {
            ExitCommand exitCommand = new ExitCommand();
            exitCommand.execute(taskList, storage);
            primaryStage.close();
        });

        // Scene Setup
        Scene scene = new Scene(layout, 400, 300);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Todo List");
        primaryStage.show();
    }

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/olivia/ui/TaskPicker.java lines 51-55:

    /**
     * Set the tasks of the task picker.
     *
     * @param tasks The list of tasks.
     */

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 Messages

possible problems in commit 882aed8:


Triggering CS2103T stats bot


  • Not in imperative mood (?)

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