Skip to content

Commit

Permalink
refactor(CommitCommand): Simplify tap functions for clarity
Browse files Browse the repository at this point in the history
- Remove an unnecessary use of the message variable in the first tap function.
- Consolidate function calls for better readability and maintainability.
- Ensure each tap function focuses on a specific task without extra dependencies.
  • Loading branch information
ityaozm@gmail.com committed Nov 19, 2024
1 parent b5407d3 commit 974bd06
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/Commands/CommitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,23 @@ public function __construct(GeneratorManager $generatorManager)
public function handle(): void
{
collect()
->tap(function () use (&$message): void {
// Ensure git is installed and the current directory is a git repository.
->tap(function (): void {
$this->createProcess(['git', 'rev-parse', '--is-inside-work-tree'])->mustRun();

})
->tap(function () use (&$cachedDiff): void {
$cachedDiff = $this->option('diff') ?: $this->createProcess($this->diffCommand())->mustRun()->getOutput();
if (empty($cachedDiff)) {
throw new RuntimeException('There are no cached files to commit. Try running `git add` to cache some files.');
}

})
->tap(function () use (&$type): void {
$type = $this->choice(
'Please choice commit type',
$types = $this->configManager->get('types'),
array_key_first($types)
);

})
->tap(function () use ($type, $cachedDiff, &$message): void {
$message = retry(
$this->option('retry-times'),
function ($attempts) use ($cachedDiff, $type): string {
Expand Down

0 comments on commit 974bd06

Please sign in to comment.