Skip to content

Commit 974bd06

Browse files
author
ityaozm@gmail.com
committed
refactor(CommitCommand): Simplify tap functions for clarity
- 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.
1 parent b5407d3 commit 974bd06

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

app/Commands/CommitCommand.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,23 @@ public function __construct(GeneratorManager $generatorManager)
6565
public function handle(): void
6666
{
6767
collect()
68-
->tap(function () use (&$message): void {
69-
// Ensure git is installed and the current directory is a git repository.
68+
->tap(function (): void {
7069
$this->createProcess(['git', 'rev-parse', '--is-inside-work-tree'])->mustRun();
71-
70+
})
71+
->tap(function () use (&$cachedDiff): void {
7272
$cachedDiff = $this->option('diff') ?: $this->createProcess($this->diffCommand())->mustRun()->getOutput();
7373
if (empty($cachedDiff)) {
7474
throw new RuntimeException('There are no cached files to commit. Try running `git add` to cache some files.');
7575
}
76-
76+
})
77+
->tap(function () use (&$type): void {
7778
$type = $this->choice(
7879
'Please choice commit type',
7980
$types = $this->configManager->get('types'),
8081
array_key_first($types)
8182
);
82-
83+
})
84+
->tap(function () use ($type, $cachedDiff, &$message): void {
8385
$message = retry(
8486
$this->option('retry-times'),
8587
function ($attempts) use ($cachedDiff, $type): string {

0 commit comments

Comments
 (0)