From 1220cd6839b82651a27dc2d040012b8500778cba Mon Sep 17 00:00:00 2001 From: Matt Stauffer Date: Sun, 18 Dec 2022 15:42:18 -0600 Subject: [PATCH] Add type hints and return type hints to CommandLine --- cli/Valet/CommandLine.php | 12 ++++++------ tests/SiteTest.php | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cli/Valet/CommandLine.php b/cli/Valet/CommandLine.php index 1696633..27cbec9 100644 --- a/cli/Valet/CommandLine.php +++ b/cli/Valet/CommandLine.php @@ -12,7 +12,7 @@ class CommandLine * @param string $command * @return void */ - public function quietly($command) + public function quietly(string $command): void { $this->runCommand($command.' > /dev/null 2>&1'); } @@ -23,7 +23,7 @@ public function quietly($command) * @param string $command * @return void */ - public function quietlyAsUser($command) + public function quietlyAsUser(string $command): void { $this->quietly('sudo -u "'.user().'" '.$command.' > /dev/null 2>&1'); } @@ -34,7 +34,7 @@ public function quietlyAsUser($command) * @param string $command * @return void */ - public function passthru($command) + public function passthru(string $command): void { passthru($command); } @@ -46,7 +46,7 @@ public function passthru($command) * @param callable $onError * @return string */ - public function run($command, callable $onError = null) + public function run(string $command, callable $onError = null): string { return $this->runCommand($command, $onError); } @@ -58,7 +58,7 @@ public function run($command, callable $onError = null) * @param callable $onError * @return string */ - public function runAsUser($command, callable $onError = null) + public function runAsUser(string $command, callable $onError = null): string { return $this->runCommand('sudo -u "'.user().'" '.$command, $onError); } @@ -70,7 +70,7 @@ public function runAsUser($command, callable $onError = null) * @param callable $onError * @return string */ - public function runCommand($command, callable $onError = null) + public function runCommand(string $command, callable $onError = null): string { $onError = $onError ?: function () { }; diff --git a/tests/SiteTest.php b/tests/SiteTest.php index 039f899..a18e237 100644 --- a/tests/SiteTest.php +++ b/tests/SiteTest.php @@ -953,15 +953,17 @@ public function test_it_can_read_php_rc_version() class CommandLineFake extends CommandLine { - public function runCommand($command, callable $onError = null) + public function runCommand(string $command, callable $onError = null): string { // noop // - // This let's us pretend like every command executes correctly + // This lets us pretend like every command executes correctly // so we can (elsewhere) ensure the things we meant to do // (like "create a certificate") look like they // happened without actually running any // commands for real. + + return 'hooray!'; } }