Skip to content

Commit cba22f3

Browse files
committed
Refactor code for restarting specific PHP version
1 parent 2399ca9 commit cba22f3

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

cli/app.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -495,27 +495,32 @@ function (ConsoleCommandEvent $event) {
495495
* Restart the daemon services.
496496
*/
497497
$app->command('restart [service]', function (OutputInterface $output, $service) {
498-
$serviceContainsPhp = is_string($service) && false !== strpos($service, 'php');
498+
switch ($service) {
499+
case '':
500+
DnsMasq::restart();
501+
PhpFpm::restart();
502+
Nginx::restart();
499503

500-
if ($service == '') {
501-
DnsMasq::restart();
502-
PhpFpm::restart();
503-
Nginx::restart();
504+
return info('Valet services have been restarted.');
505+
case 'dnsmasq':
506+
DnsMasq::restart();
504507

505-
return info('Valet services have been restarted.');
506-
} elseif ($service == 'dnsmasq') {
507-
DnsMasq::restart();
508+
return info('dnsmasq has been restarted.');
509+
case 'nginx':
510+
Nginx::restart();
508511

509-
return info('dnsmasq has been restarted.');
510-
} elseif ($service == 'nginx') {
511-
Nginx::restart();
512+
return info('Nginx has been restarted.');
513+
case 'php':
514+
PhpFpm::restart();
515+
516+
return info('PHP has been restarted.');
517+
}
512518

513-
return info('Nginx has been restarted.');
514-
} elseif ($serviceContainsPhp) {
515-
$hasSpecifiedVersion = $service !== 'php';
516-
PhpFpm::restart($hasSpecifiedVersion ? PhpFpm::normalizePhpVersion($service) : null);
519+
// Handle restarting specific PHP version (e.g. `valet restart [email protected]`)
520+
if (str_contains($service, 'php')) {
521+
PhpFpm::restart($normalized = PhpFpm::normalizePhpVersion($service));
517522

518-
return info('PHP has been restarted.');
523+
return info($normalized . ' has been restarted.');
519524
}
520525

521526
return warning(sprintf('Invalid valet service name [%s]', $service));

tests/CliTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ public function test_restart_command_restarts_php_version()
792792
$tester->run(['command' => 'restart', 'service' => '[email protected]']);
793793
$tester->assertCommandIsSuccessful();
794794

795-
$this->assertStringContainsString('PHP has been restarted.', $tester->getDisplay());
795+
$this->assertStringContainsString('[email protected] has been restarted.', $tester->getDisplay());
796796
}
797797

798798
public function test_restart_command_restarts_php_denormalized_version()
@@ -813,7 +813,7 @@ public function test_restart_command_restarts_php_denormalized_version()
813813
$tester->run(['command' => 'restart', 'service' => 'php81']);
814814
$tester->assertCommandIsSuccessful();
815815

816-
$this->assertStringContainsString('PHP has been restarted.', $tester->getDisplay());
816+
$this->assertStringContainsString('[email protected] has been restarted.', $tester->getDisplay());
817817
}
818818

819819
public function test_start_command()

0 commit comments

Comments
 (0)