refactor: consolidate console io into ioservice - #42
Conversation
Consolidate input gathering and output formatting from separate traits and PrompterService into a single DI-injected IOService. Includes wrappers for Laravel Prompts with spacing suppression, validation helpers, and custom styling methods.
Update BaseCommand constructor and initialize() to inject and setup IOService. Remove obsolete traits and PrompterService dependency. Adjust test fixtures and helpers accordingly.
Update all console commands and ServerHelpersTrait to use IOService methods. Remove obsolete PrompterService, ConsoleInputTrait, ConsoleOutputTrait, and related tests.
Reorder service parameters in BaseCommand constructor to follow alphabetical order (env, inventory, io, proc). Add comment in IOService initialize() explaining command usage for input inspection. Update TestConsoleCommand constructor and docblock to match new order. Align mockCommandContainer() parameters, assignments, and bindings in TestHelpers.php with alphabetical order, including updated comment.
WalkthroughRefactors console I/O to a centralized IOService. BaseCommand is updated to depend on IOService, commands/traits switch from direct/trait-based helpers to $this->io methods, PrompterService and Console* traits are removed, and tests are updated accordingly with new IOService tests and fixture changes. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant CLI as Symfony Console
participant Cmd as Command (e.g., ServerAddCommand)
participant IO as IOService
Note over CLI,Cmd: Command lifecycle
User->>CLI: run command
CLI->>Cmd: construct (inject IOService)
CLI->>Cmd: initialize(Input, Output)
Cmd->>IO: initialize(Cmd, Input, Output)
Note over Cmd,IO: Execution phase
CLI->>Cmd: execute()
Cmd->>IO: h1/hr/writeln(...)
alt needs input
Cmd->>IO: getOptionOrPrompt(...)
IO-->>Cmd: value or null
end
alt validation ok
Cmd->>IO: success(...)
else validation error
Cmd->>IO: error(...)/warning(...)
Cmd-->>CLI: return with failure/same code path
end
Cmd-->>CLI: return status
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (17)
💤 Files with no reviewable changes (6)
🧰 Additional context used📓 Path-based instructions (10)**/*.php📄 CodeRabbit inference engine (.cursor/rules/00-main.mdc)
Files:
**/*Command.php📄 CodeRabbit inference engine (.cursor/rules/01-architecture.mdc)
Files:
app/{Contracts/BaseCommand.php,Traits/ConsoleOutputTrait.php}📄 CodeRabbit inference engine (.cursor/rules/03-commands.mdc)
Files:
app/Contracts/BaseCommand.php📄 CodeRabbit inference engine (.cursor/rules/03-commands.mdc)
Files:
{tests/**,test/**,**/*@(Test|Spec).php}📄 CodeRabbit inference engine (.cursor/rules/00-main.mdc)
Files:
tests/**/*.php📄 CodeRabbit inference engine (.cursor/rules/01-architecture.mdc)
Files:
app/Console/**/*Command.php📄 CodeRabbit inference engine (.cursor/rules/03-commands.mdc)
Files:
tests/TestHelpers.php📄 CodeRabbit inference engine (.cursor/rules/02-tests.mdc)
Files:
**/*Service.php📄 CodeRabbit inference engine (.cursor/rules/01-architecture.mdc)
Files:
app/Services/**/*.php📄 CodeRabbit inference engine (.cursor/rules/03-commands.mdc)
Files:
🧠 Learnings (12)📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:50:03.829ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:50:03.829ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
📚 Learning: 2025-10-12T15:51:30.236ZApplied to files:
🧬 Code graph analysis (11)app/Contracts/BaseCommand.php (2)
tests/Fixtures/TestConsoleCommand.php (2)
app/Traits/ServerHelpersTrait.php (1)
app/Console/Server/ServerAddCommand.php (2)
tests/TestHelpers.php (2)
app/Console/Server/ServerDeleteCommand.php (1)
tests/Unit/Contracts/BaseCommandTest.php (1)
app/Console/HelloCommand.php (1)
app/Console/Server/ServerListCommand.php (1)
tests/Unit/Services/IOServiceTest.php (3)
app/Services/IOService.php (1)
🪛 PHPMD (2.15.0)tests/Fixtures/TestConsoleCommand.php204-204: Avoid unused parameters such as '$value'. (undefined) (UnusedFormalParameter) 284-284: Avoid unused parameters such as '$q'. (undefined) (UnusedFormalParameter) 🔇 Additional comments (14)
Comment |
Summary by CodeRabbit