Skip to content

Commit

Permalink
refactor(CommitCommand): Change visibility of methods
Browse files Browse the repository at this point in the history
- Change the visibility of several methods from protected to private
- Refactor the createProcess method to use the tap function
  • Loading branch information
guanguans committed Jun 30, 2023
1 parent cc999c3 commit 6f96be3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
30 changes: 14 additions & 16 deletions app/Commands/CommitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,31 +209,29 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
}

/**
* @param array|string $command
* @param null|mixed $input
*
* @noinspection CallableParameterUseCaseInTypeContextInspection
*/
protected function createProcess($command, ?string $cwd = null, ?array $env = null, $input = null, ?float $timeout = 60): Process
private function createProcess(array $command, ?string $cwd = null, ?array $env = null, $input = null, ?float $timeout = 60): Process
{
null === $cwd and $cwd = $this->argument('path');
$process = \is_string($command)
? Process::fromShellCommandline($command, $cwd, $env, $input, $timeout) // @codeCoverageIgnore
: new Process($command, $cwd, $env, $input, $timeout);

if ($this->option('verbose')) {
$this->output->info($process->getCommandLine());
if (null === $cwd) {
$cwd = $this->argument('path');
}

return $process;
return tap(new Process($command, $cwd, $env, $input, $timeout), function (Process $process): void {
if ($this->option('verbose')) {
$this->output->info($process->getCommandLine());
}
});
}

protected function getDiffCommand(): array
private function getDiffCommand(): array
{
return array_merge(['git', 'diff', '--cached'], $this->option('diff-options'));
}

protected function getPrompt(string $cachedDiff): string
private function getPrompt(string $cachedDiff): string
{
return (string) str($this->configManager->get("prompts.{$this->option('prompt')}"))
->replace($this->configManager->get('diff_mark'), $cachedDiff)
Expand All @@ -244,7 +242,7 @@ protected function getPrompt(string $cachedDiff): string
});
}

protected function tryFixMessages(string $messages): string
private function tryFixMessages(string $messages): string
{
return (new JsonFixer())
// ->missingValue('')
Expand All @@ -257,7 +255,7 @@ protected function tryFixMessages(string $messages): string
*
* @noinspection CallableParameterUseCaseInTypeContextInspection
*/
protected function getCommitCommand(array $message): array
private function getCommitCommand(array $message): array
{
$options = collect($this->option('commit-options'))
->push('--edit')
Expand All @@ -280,12 +278,12 @@ protected function getCommitCommand(array $message): array
return array_merge(['git', 'commit', '--message', $message], $options);
}

protected function isEditMode(): bool
private function isEditMode(): bool
{
return ! windows_os() && ! $this->option('no-edit') && $this->configManager->get('edit');
}

protected function isNotEditMode(): bool
private function isNotEditMode(): bool
{
return ! $this->isEditMode();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Commands/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
* @throws \JsonException
* @noinspection PhpInconsistentReturnPointsInspection
*/
protected function argToValue(string $arg)
private function argToValue(string $arg)
{
if (0 === strncasecmp($arg, 'null', 4)) {
return;
Expand Down Expand Up @@ -238,7 +238,7 @@ protected function argToValue(string $arg)
* @noinspection DebugFunctionUsageInspection
* @noinspection JsonEncodingApiUsageInspection
*/
protected function valueToArg($value): string
private function valueToArg($value): string
{
if (null === $value) {
return 'null';
Expand Down

0 comments on commit 6f96be3

Please sign in to comment.