Skip to content

Commit

Permalink
Rearrange code to make it easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianfeldmann committed Dec 14, 2023
1 parent d2274c6 commit 2298b62
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,24 @@ public static function getSubscribedEvents(): array
public function installHooks(Event $event): void
{
$this->io->write('<info>CaptainHook Hook Installer</info>');

if ($this->shouldExecutionBeSkipped()) {
return;
}
$this->detectConfiguration();
$this->detectCaptainExecutable();
$this->detectGitDir();

if ($this->shouldExecutionBeSkipped()) {
if ($this->dotGit->isAdditionalWorktree()) {
$this->displayGitWorktreeInfo();
return;
}
if (!file_exists($this->executable)) {
$this->writeNoExecutableHelp();
$this->displayNoExecutableInfo();
return;
}

if (!file_exists($this->configuration)) {
$this->writeNoConfigHelp();
$this->displayNoConfigInfo();
return;
}

Expand Down Expand Up @@ -204,12 +209,6 @@ private function shouldExecutionBeSkipped(): bool
$this->io->write(' <comment>disabling plugin due to CI-environment</comment>');
return true;
}

$this->detectGitDir();
if ($this->dotGit->isAdditionalWorktree()) {
$this->io->write(' <comment>ARRRRR! We ARRR in a worktree, install is skipped!</comment>');
return true;
}
return false;
}

Expand Down Expand Up @@ -248,12 +247,22 @@ private function install(): void
}
}

/**
* Displays some message to make the user aware that the plugin is doing nothing because we are in a worktree
*
* @return void
*/
private function displayGitWorktreeInfo(): void
{
$this->io->write(' <comment>ARRRRR! We ARRR in a worktree, install is skipped!</comment>');
}

/**
* Displays a helpful message to the user if the captainhook executable could not be found
*
* @return void
*/
private function writeNoExecutableHelp(): void
private function displayNoExecutableInfo(): void
{
$this->io->write(
' <comment>CaptainHook executable not found</comment>' . PHP_EOL .
Expand All @@ -280,7 +289,7 @@ private function writeNoExecutableHelp(): void
*
* @return void
*/
private function writeNoConfigHelp(): void
private function displayNoConfigInfo(): void
{
$this->io->write(
' <comment>CaptainHook configuration not found</comment>' . PHP_EOL .
Expand Down

0 comments on commit 2298b62

Please sign in to comment.