Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 17, 2024
1 parent ef9f635 commit d2003b6
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/TextUI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ public function run(array $argv): int
$this->loadBootstrapScript($configuration->bootstrap());
}

$this->executeCommandsThatRequireCompleteConfiguration($configuration, $cliConfiguration);
$this->executeCommandsThatDoNotRequireTheTestSuite($configuration, $cliConfiguration);

$testSuite = $this->buildTestSuite($configuration);

$this->executeCommandsThatRequireCliConfigurationAndTestSuite($cliConfiguration, $testSuite);
$this->executeHelpCommandWhenThereIsNothingElseToDo($configuration, $testSuite);
$this->executeCommandsThatRequireTheTestSuite($configuration, $cliConfiguration, $testSuite);

if ($testSuite->isEmpty() && !$configuration->hasCliArguments() && $configuration->testSuite()->isEmpty()) {
$this->execute(new ShowHelpCommand(Result::FAILURE));
}

$pharExtensions = null;
$extensionRequiresCodeCoverageCollection = false;
Expand Down Expand Up @@ -400,7 +403,18 @@ private function executeCommandsThatOnlyRequireCliConfiguration(CliConfiguration
}
}

private function executeCommandsThatRequireCliConfigurationAndTestSuite(CliConfiguration $cliConfiguration, TestSuite $testSuite): void
private function executeCommandsThatDoNotRequireTheTestSuite(Configuration $configuration, CliConfiguration $cliConfiguration): void
{
if ($cliConfiguration->listSuites()) {
$this->execute(new ListTestSuitesCommand($configuration->testSuite()));
}

if ($cliConfiguration->warmCoverageCache()) {
$this->execute(new WarmCodeCoverageCacheCommand($configuration, CodeCoverageFilterRegistry::instance()));
}
}

private function executeCommandsThatRequireTheTestSuite(Configuration $configuration, CliConfiguration $cliConfiguration, TestSuite $testSuite): void
{
if ($cliConfiguration->listGroups()) {
$this->execute(new ListGroupsCommand($testSuite));
Expand All @@ -424,24 +438,6 @@ private function executeCommandsThatRequireCliConfigurationAndTestSuite(CliConfi
}
}

private function executeCommandsThatRequireCompleteConfiguration(Configuration $configuration, CliConfiguration $cliConfiguration): void
{
if ($cliConfiguration->listSuites()) {
$this->execute(new ListTestSuitesCommand($configuration->testSuite()));
}

if ($cliConfiguration->warmCoverageCache()) {
$this->execute(new WarmCodeCoverageCacheCommand($configuration, CodeCoverageFilterRegistry::instance()));
}
}

private function executeHelpCommandWhenThereIsNothingElseToDo(Configuration $configuration, TestSuite $testSuite): void
{
if ($testSuite->isEmpty() && !$configuration->hasCliArguments() && $configuration->testSuite()->isEmpty()) {
$this->execute(new ShowHelpCommand(Result::FAILURE));
}
}

private function writeRuntimeInformation(Printer $printer, Configuration $configuration): void
{
$printer->print(Version::getVersionString() . PHP_EOL . PHP_EOL);
Expand Down

0 comments on commit d2003b6

Please sign in to comment.