diff --git a/Command/DebugCommand.php b/Command/DebugCommand.php index 0315b77..5729b94 100644 --- a/Command/DebugCommand.php +++ b/Command/DebugCommand.php @@ -40,14 +40,10 @@ final class DebugCommand extends Command */ protected static $defaultDescription = 'List all dotenv files with variables and values'; - private string $kernelEnvironment; - private string $projectDirectory; - - public function __construct(string $kernelEnvironment, string $projectDirectory) - { - $this->kernelEnvironment = $kernelEnvironment; - $this->projectDirectory = $projectDirectory; - + public function __construct( + private string $kernelEnvironment, + private string $projectDirectory, + ) { parent::__construct(); } @@ -98,18 +94,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int $envFiles = $this->getEnvFiles($filePath); $availableFiles = array_filter($envFiles, 'is_file'); - if (\in_array(sprintf('%s.local.php', $filePath), $availableFiles, true)) { - $io->warning(sprintf('Due to existing dump file (%s.local.php) all other dotenv files are skipped.', $this->getRelativeName($filePath))); + if (\in_array(\sprintf('%s.local.php', $filePath), $availableFiles, true)) { + $io->warning(\sprintf('Due to existing dump file (%s.local.php) all other dotenv files are skipped.', $this->getRelativeName($filePath))); } - if (is_file($filePath) && is_file(sprintf('%s.dist', $filePath))) { - $io->warning(sprintf('The file %s.dist gets skipped due to the existence of %1$s.', $this->getRelativeName($filePath))); + if (is_file($filePath) && is_file(\sprintf('%s.dist', $filePath))) { + $io->warning(\sprintf('The file %s.dist gets skipped due to the existence of %1$s.', $this->getRelativeName($filePath))); } $io->section('Scanned Files (in descending priority)'); $io->listing(array_map(fn (string $envFile) => \in_array($envFile, $availableFiles, true) - ? sprintf('✓ %s', $this->getRelativeName($envFile)) - : sprintf('⨯ %s', $this->getRelativeName($envFile)), $envFiles)); + ? \sprintf('✓ %s', $this->getRelativeName($envFile)) + : \sprintf('⨯ %s', $this->getRelativeName($envFile)), $envFiles)); $nameFilter = $input->getArgument('filter'); $variables = $this->getVariables($availableFiles, $nameFilter); @@ -124,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->comment('Note that values might be different between web and CLI.'); } else { - $io->warning(sprintf('No variables match the given filter "%s".', $nameFilter)); + $io->warning(\sprintf('No variables match the given filter "%s".', $nameFilter)); } return 0; @@ -188,17 +184,17 @@ private function getAvailableVars(): array private function getEnvFiles(string $filePath): array { $files = [ - sprintf('%s.local.php', $filePath), - sprintf('%s.%s.local', $filePath, $this->kernelEnvironment), - sprintf('%s.%s', $filePath, $this->kernelEnvironment), + \sprintf('%s.local.php', $filePath), + \sprintf('%s.%s.local', $filePath, $this->kernelEnvironment), + \sprintf('%s.%s', $filePath, $this->kernelEnvironment), ]; if ('test' !== $this->kernelEnvironment) { - $files[] = sprintf('%s.local', $filePath); + $files[] = \sprintf('%s.local', $filePath); } - if (!is_file($filePath) && is_file(sprintf('%s.dist', $filePath))) { - $files[] = sprintf('%s.dist', $filePath); + if (!is_file($filePath) && is_file(\sprintf('%s.dist', $filePath))) { + $files[] = \sprintf('%s.dist', $filePath); } else { $files[] = $filePath; } diff --git a/Command/DotenvDumpCommand.php b/Command/DotenvDumpCommand.php index 37383dc..8a367a3 100644 --- a/Command/DotenvDumpCommand.php +++ b/Command/DotenvDumpCommand.php @@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int EOF; file_put_contents($dotenvPath.'.local.php', $vars, \LOCK_EX); - $output->writeln(sprintf('Successfully dumped .env files in .env.local.php for the %s environment.', $env)); + $output->writeln(\sprintf('Successfully dumped .env files in .env.local.php for the %s environment.', $env)); return 0; } diff --git a/Dotenv.php b/Dotenv.php index b20f6b5..a667365 100644 --- a/Dotenv.php +++ b/Dotenv.php @@ -461,7 +461,7 @@ private function resolveCommands(string $value, array $loadedVars): string try { $process->mustRun(); } catch (ProcessException) { - throw $this->createFormatException(sprintf('Issue expanding a command (%s)', $process->getErrorOutput())); + throw $this->createFormatException(\sprintf('Issue expanding a command (%s)', $process->getErrorOutput())); } return rtrim($process->getOutput(), "\n\r"); @@ -485,7 +485,7 @@ private function resolveVariables(string $value, array $loadedVars): string (?P\})? # optional closing brace /x'; - $value = preg_replace_callback($regex, function ($matches) use ($loadedVars) { + return preg_replace_callback($regex, function ($matches) use ($loadedVars) { // odd number of backslashes means the $ character is escaped if (1 === \strlen($matches['backslashes']) % 2) { return substr($matches[0], 1); @@ -516,7 +516,7 @@ private function resolveVariables(string $value, array $loadedVars): string if ('' === $value && isset($matches['default_value']) && '' !== $matches['default_value']) { $unsupportedChars = strpbrk($matches['default_value'], '\'"{$'); if (false !== $unsupportedChars) { - throw $this->createFormatException(sprintf('Unsupported character "%s" found in the default value of variable "$%s".', $unsupportedChars[0], $name)); + throw $this->createFormatException(\sprintf('Unsupported character "%s" found in the default value of variable "$%s".', $unsupportedChars[0], $name)); } $value = substr($matches['default_value'], 2); @@ -532,8 +532,6 @@ private function resolveVariables(string $value, array $loadedVars): string return $matches['backslashes'].$value; }, $value); - - return $value; } private function moveCursor(string $text): void diff --git a/Exception/FormatException.php b/Exception/FormatException.php index 81c00bb..92dfa13 100644 --- a/Exception/FormatException.php +++ b/Exception/FormatException.php @@ -24,7 +24,7 @@ public function __construct( int $code = 0, ?\Throwable $previous = null, ) { - parent::__construct(sprintf("%s in \"%s\" at line %d.\n%s", $message, $context->getPath(), $context->getLineno(), $context->getDetails()), $code, $previous); + parent::__construct(\sprintf("%s in \"%s\" at line %d.\n%s", $message, $context->getPath(), $context->getLineno(), $context->getDetails()), $code, $previous); } public function getContext(): FormatExceptionContext diff --git a/Exception/PathException.php b/Exception/PathException.php index e432b2e..568b009 100644 --- a/Exception/PathException.php +++ b/Exception/PathException.php @@ -20,6 +20,6 @@ final class PathException extends \RuntimeException implements ExceptionInterfac { public function __construct(string $path, int $code = 0, ?\Throwable $previous = null) { - parent::__construct(sprintf('Unable to read the "%s" environment file.', $path), $code, $previous); + parent::__construct(\sprintf('Unable to read the "%s" environment file.', $path), $code, $previous); } }