Skip to content

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

@soc-se-bot-red

Description

@soc-se-bot-red

@Nicholascyx 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/kafka/Parser.java lines 24-118:

    public static void parseCommand(String userInput, TaskList taskList, Storage storage, Ui ui) throws KafkaException, IOException, DateTimeParseException {
        String[] splitInput = userInput.trim().split(" ", 2);

        if (splitInput[0] == null) {
            return;
        }

        String command = splitInput[0].toLowerCase();
        String arguments = splitInput.length > 1 ? splitInput[1] : "";

        switch (command) {
            case "bye":
                Kafka.exitChat();
                break;
            case "list":
                ui.getList();
                taskList.printList();
                break;
            case "mark":
                int taskNumberMark = Integer.parseInt(arguments);
                Task taskToMark = taskList.tasks.get(taskNumberMark - 1);
                taskList.mark(taskToMark);
                storage.writeToFile(taskList.tasks);
                ui.mark(taskToMark);
                break;
            case "unmark":
                int taskNumberUnmark = Integer.parseInt(arguments);
                Task taskToUnmark = taskList.tasks.get(taskNumberUnmark - 1);
                taskList.unmark(taskToUnmark);
                storage.writeToFile(taskList.tasks);
                ui.unmark(taskToUnmark);
                break;
            case "delete":
                if (taskList.tasks.isEmpty()) {
                    return;
                }
                int taskNumberDelete = Integer.parseInt(arguments);
                Task taskToDelete = taskList.tasks.get(taskNumberDelete - 1);
                taskList.delete(taskNumberDelete);
                storage.writeToFile(taskList.tasks);
                ui.delete(taskToDelete, taskList);
                break;
            case "find":
                if (arguments.isEmpty()) {
                    throw new KafkaException("It seems you've left the details blank. Even the simplest tasks need some direction, don't you think?");
                }
                TaskList temp = taskList.find(arguments.toLowerCase());
                if (temp.isEmpty()) {
                    throw new KafkaException("Hmm, it seems that no task aligns with that word... mind trying again?");
                }
                ui.find();
                temp.printList();
                break;
            case "todo":
                if (arguments.isEmpty()) {
                    throw new KafkaException("It seems you've left the details blank. Even the simplest tasks need some direction, don't you think?");
                }
                Task todo = new Todo(arguments, false);
                taskList.addTask(todo);
                storage.writeToFile(taskList.tasks);
                ui.addTask(todo, taskList);
                break;
            case "deadline":
                if (arguments.isEmpty()) {
                    throw new KafkaException("It seems you've left the details blank. Even the simplest tasks need some direction, don't you think?");
                }
                String[] deadlineParts = arguments.split("/by ");
                if (deadlineParts.length < 2) {
                    throw new KafkaException("It appears the details for this deadline task are off. Let's give it another go, shall we?");
                }
                LocalDateTime by = LocalDateTimeConverter.getLocalDateTime(deadlineParts[1]);
                Task deadline = new Deadline(deadlineParts[0], by, false);
                taskList.addTask(deadline);
                storage.writeToFile(taskList.tasks);
                ui.addTask(deadline, taskList);
                break;
            case "event":
                if (arguments.isEmpty()) {
                    throw new KafkaException("It seems you've left the details blank. Even the simplest tasks need some direction, don't you think?");
                }
                String[] eventParts = arguments.split("/from | /to ");
                if (eventParts.length < 3) {
                    throw new KafkaException("It appears the details for this event task are off. Let's give it another go, shall we?");
                }
                LocalDateTime from = LocalDateTimeConverter.getLocalDateTime(eventParts[1]);
                LocalDateTime to = LocalDateTimeConverter.getLocalDateTime(eventParts[2]);
                Task event = new Event(eventParts[0], from, to, false);
                taskList.addTask(event);
                storage.writeToFile(taskList.tasks);
                ui.addTask(event, taskList);
                break;
            default:
                throw new KafkaException("Hmm... I'm not sure what you're getting at. Care to enlighten me?");
        }
    }

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

No easy-to-detect issues 👍

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions