diff --git a/cli/Valet/Brew.php b/cli/Valet/Brew.php index 121a13935..33d597bc8 100644 --- a/cli/Valet/Brew.php +++ b/cli/Valet/Brew.php @@ -292,7 +292,7 @@ function ($version) use ($resolvedPhpVersion) { * * @param string|null $phpVersion For example, "php@8.1" */ - public function getPhpExecutablePath(string $phpVersion = null): string + public function getPhpExecutablePath(?string $phpVersion = null): string { if (! $phpVersion) { return BREW_PREFIX.'/bin/php'; diff --git a/cli/Valet/CommandLine.php b/cli/Valet/CommandLine.php index 186d093bf..3d1841834 100644 --- a/cli/Valet/CommandLine.php +++ b/cli/Valet/CommandLine.php @@ -33,7 +33,7 @@ public function passthru(string $command): void /** * Run the given command as the non-root user. */ - public function run(string $command, callable $onError = null): string + public function run(string $command, ?callable $onError = null): string { return $this->runCommand($command, $onError); } @@ -41,7 +41,7 @@ public function run(string $command, callable $onError = null): string /** * Run the given command. */ - public function runAsUser(string $command, callable $onError = null): string + public function runAsUser(string $command, ?callable $onError = null): string { return $this->runCommand('sudo -u "'.user().'" '.$command, $onError); } @@ -49,7 +49,7 @@ public function runAsUser(string $command, callable $onError = null): string /** * Run the given command. */ - public function runCommand(string $command, callable $onError = null): string + public function runCommand(string $command, ?callable $onError = null): string { $onError = $onError ?: function () { }; diff --git a/cli/Valet/Expose.php b/cli/Valet/Expose.php index 7f9651c48..abb1428c0 100644 --- a/cli/Valet/Expose.php +++ b/cli/Valet/Expose.php @@ -11,7 +11,7 @@ public function __construct(public Composer $composer, public CommandLine $cli) { } - public function currentTunnelUrl(string $domain = null): ?string + public function currentTunnelUrl(?string $domain = null): ?string { $endpoint = 'http://127.0.0.1:4040/api/tunnels'; diff --git a/cli/Valet/Filesystem.php b/cli/Valet/Filesystem.php index eaeb1232c..3b16d7f94 100644 --- a/cli/Valet/Filesystem.php +++ b/cli/Valet/Filesystem.php @@ -19,7 +19,7 @@ public function isDir(string $path): bool /** * Create a directory. */ - public function mkdir(string $path, string $owner = null, int $mode = 0755): void + public function mkdir(string $path, ?string $owner = null, int $mode = 0755): void { mkdir($path, $mode, true); @@ -31,7 +31,7 @@ public function mkdir(string $path, string $owner = null, int $mode = 0755): voi /** * Ensure that the given directory exists. */ - public function ensureDirExists(string $path, string $owner = null, int $mode = 0755): void + public function ensureDirExists(string $path, ?string $owner = null, int $mode = 0755): void { if (! $this->isDir($path)) { $this->mkdir($path, $owner, $mode); @@ -49,7 +49,7 @@ public function mkdirAsUser(string $path, int $mode = 0755): void /** * Touch the given path. */ - public function touch(string $path, string $owner = null): string + public function touch(string $path, ?string $owner = null): string { touch($path); @@ -87,7 +87,7 @@ public function get(string $path): string /** * Write to the given file. */ - public function put(string $path, string $contents, string $owner = null): void + public function put(string $path, string $contents, ?string $owner = null): void { file_put_contents($path, $contents); @@ -107,7 +107,7 @@ public function putAsUser(string $path, ?string $contents): void /** * Append the contents to the given file. */ - public function append(string $path, string $contents, string $owner = null): void + public function append(string $path, string $contents, ?string $owner = null): void { file_put_contents($path, $contents, FILE_APPEND); diff --git a/cli/Valet/Ngrok.php b/cli/Valet/Ngrok.php index 222806677..c7c0d11d4 100644 --- a/cli/Valet/Ngrok.php +++ b/cli/Valet/Ngrok.php @@ -20,7 +20,7 @@ public function __construct(public CommandLine $cli, public Brew $brew) /** * Get the current tunnel URL from the Ngrok API. */ - public function currentTunnelUrl(string $domain = null): string + public function currentTunnelUrl(?string $domain = null): string { // wait a second for ngrok to start before attempting to find available tunnels sleep(1); diff --git a/cli/Valet/PhpFpm.php b/cli/Valet/PhpFpm.php index 75c92d896..9c5e86c92 100644 --- a/cli/Valet/PhpFpm.php +++ b/cli/Valet/PhpFpm.php @@ -102,7 +102,7 @@ public function createConfigurationFiles(string $phpVersion): void /** * Restart the PHP FPM process (if one specified) or processes (if none specified). */ - public function restart(string $phpVersion = null): void + public function restart(?string $phpVersion = null): void { $this->brew->restartService($phpVersion ?: $this->utilizedPhpVersions()); } @@ -122,7 +122,7 @@ public function stop(): void /** * Get the path to the FPM configuration file for the current PHP version. */ - public function fpmConfigPath(string $phpVersion = null): string + public function fpmConfigPath(?string $phpVersion = null): string { if (! $phpVersion) { $phpVersion = $this->brew->linkedPhp(); @@ -152,7 +152,7 @@ public function stopRunning(): void /** * Stop a given PHP version, if that specific version isn't being used globally or by any sites. */ - public function stopIfUnused(string $phpVersion = null): void + public function stopIfUnused(?string $phpVersion = null): void { if (! $phpVersion) { return; @@ -305,7 +305,7 @@ public function validateRequestedVersion(string $version): string /** * Get FPM sock file name for a given PHP version. */ - public static function fpmSockName(string $phpVersion = null): string + public static function fpmSockName(?string $phpVersion = null): string { $versionInteger = preg_replace('~[^\d]~', '', $phpVersion); diff --git a/cli/Valet/Site.php b/cli/Valet/Site.php index 214e2e5e2..4a29cd503 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -188,7 +188,7 @@ public function getSiteUrl(string $directory): string /** * Identify whether a site is for a proxy by reading the host name from its config file. */ - public function getProxyHostForSite(string $site, string $configContents = null): ?string + public function getProxyHostForSite(string $site, ?string $configContents = null): ?string { $siteConf = $configContents ?: $this->getSiteConfigFileContents($site); @@ -207,7 +207,7 @@ public function getProxyHostForSite(string $site, string $configContents = null) /** * Get the contents of the configuration for the given site. */ - public function getSiteConfigFileContents(string $site, string $suffix = null): ?string + public function getSiteConfigFileContents(string $site, ?string $suffix = null): ?string { $config = $this->config->read(); $suffix = $suffix ?: '.'.$config['tld']; @@ -219,7 +219,7 @@ public function getSiteConfigFileContents(string $site, string $suffix = null): /** * Get all certificates from config folder. */ - public function getCertificates(string $path = null): Collection + public function getCertificates(?string $path = null): Collection { $path = $path ?: $this->certificatesPath(); @@ -283,7 +283,7 @@ public function getSites(string $path, Collection $certs): Collection /** * Unlink the given symbolic link. */ - public function unlink(string $name = null): string + public function unlink(?string $name = null): string { $name = $this->getSiteLinkName($name); @@ -452,7 +452,7 @@ public function isSecured(string $site): bool * * @see https://github.com/cabforum/servercert/blob/main/docs/BR.md */ - public function secure(string $url, string $siteConf = null, int $certificateExpireInDays = 396, int $caExpireInYears = 20): void + public function secure(string $url, ?string $siteConf = null, int $certificateExpireInDays = 396, int $caExpireInYears = 20): void { // Extract in order to later preserve custom PHP version config when securing $phpVersion = $this->customPhpVersion($url); @@ -637,7 +637,7 @@ public function buildCertificateConf(string $path, string $url): void /** * Build the TLS secured Nginx server for the given URL. */ - public function buildSecureNginxServer(string $url, string $siteConf = null): string + public function buildSecureNginxServer(string $url, ?string $siteConf = null): string { if ($siteConf === null) { $siteConf = $this->replaceOldLoopbackWithNew( @@ -952,7 +952,7 @@ public function plistPath(): string /** * Get the path to Nginx site configuration files. */ - public function nginxPath(string $additionalPath = null): string + public function nginxPath(?string $additionalPath = null): string { return $this->valetHomePath().'/Nginx'.($additionalPath ? '/'.$additionalPath : ''); } @@ -960,7 +960,7 @@ public function nginxPath(string $additionalPath = null): string /** * Get the path to the linked Valet sites. */ - public function sitesPath(string $link = null): string + public function sitesPath(?string $link = null): string { return $this->valetHomePath().'/Sites'.($link ? '/'.$link : ''); } @@ -968,7 +968,7 @@ public function sitesPath(string $link = null): string /** * Get the path to the Valet CA certificates. */ - public function caPath(string $caFile = null): string + public function caPath(?string $caFile = null): string { return $this->valetHomePath().'/CA'.($caFile ? '/'.$caFile : ''); } @@ -976,7 +976,7 @@ public function caPath(string $caFile = null): string /** * Get the path to the Valet TLS certificates. */ - public function certificatesPath(string $url = null, string $extension = null): string + public function certificatesPath(?string $url = null, ?string $extension = null): string { $url = $url ? '/'.$url : ''; $extension = $extension ? '.'.$extension : ''; @@ -1060,7 +1060,7 @@ public function replaceSockFile(string $siteConf, string $phpVersion): string /** * Get configuration items defined in .valetrc for a site. */ - public function valetRc(string $siteName, string $cwd = null): array + public function valetRc(string $siteName, ?string $cwd = null): array { if ($cwd) { $path = $cwd.'/.valetrc'; @@ -1086,7 +1086,7 @@ public function valetRc(string $siteName, string $cwd = null): array /** * Get PHP version from .valetrc or .valetphprc for a site. */ - public function phpRcVersion(string $siteName, string $cwd = null): ?string + public function phpRcVersion(string $siteName, ?string $cwd = null): ?string { if ($cwd) { $oldPath = $cwd.'/.valetphprc'; diff --git a/cli/includes/helpers.php b/cli/includes/helpers.php index 475594f05..f9d0ce89e 100644 --- a/cli/includes/helpers.php +++ b/cli/includes/helpers.php @@ -32,7 +32,7 @@ /** * Set or get a global console writer. */ -function writer(OutputInterface $writer = null): OutputInterface|\NullWriter|null +function writer(?OutputInterface $writer = null): OutputInterface|\NullWriter|null { $container = Container::getInstance(); diff --git a/find-usable-php.php b/find-usable-php.php index 9ff3869d9..7af434ae9 100644 --- a/find-usable-php.php +++ b/find-usable-php.php @@ -52,7 +52,7 @@ * @param string|null $phpFormulaName For example, "php@8.1" * @return string */ -function getPhpExecutablePath(string $phpFormulaName = null) +function getPhpExecutablePath(?string $phpFormulaName = null) { $brewPrefix = exec('printf $(brew --prefix)'); diff --git a/tests/PhpFpmTest.php b/tests/PhpFpmTest.php index 9d4e50335..232b45c77 100644 --- a/tests/PhpFpmTest.php +++ b/tests/PhpFpmTest.php @@ -449,7 +449,7 @@ public function test_isolate_will_throw_if_site_is_not_parked_or_linked() class StubForUpdatingFpmConfigFiles extends PhpFpm { - public function fpmConfigPath(string $phpVersion = null): string + public function fpmConfigPath(?string $phpVersion = null): string { return __DIR__.'/output/fpm.conf'; } diff --git a/tests/SiteTest.php b/tests/SiteTest.php index d941b258c..d6201678a 100644 --- a/tests/SiteTest.php +++ b/tests/SiteTest.php @@ -1161,7 +1161,7 @@ public function test_it_can_read_php_rc_version() class CommandLineFake extends CommandLine { - public function runCommand(string $command, callable $onError = null): string + public function runCommand(string $command, ?callable $onError = null): string { // noop // @@ -1284,7 +1284,7 @@ public function assertCertificateExistsWithCounterValue($urlWithTld, $counter) class StubForRemovingLinks extends Site { - public function sitesPath(string $additionalPath = null): string + public function sitesPath(?string $additionalPath = null): string { return __DIR__.'/output'.($additionalPath ? '/'.$additionalPath : ''); }