diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index a965a7b45..d617f9f4c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -4,16 +4,12 @@ return (new PhpCsFixer\Config()) ->setFinder($finder) - ->setRules(array( + ->setRules([ '@Symfony' => true, '@Symfony:risky' => true, 'fopen_flags' => false, - '@PHPUnit48Migration:risky' => true, - 'array_syntax' => ['syntax' => 'short'], - 'ordered_imports' => true, - 'php_unit_no_expectation_annotation' => false, // part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice - 'nullable_type_declaration_for_default_null_value' => true, + 'modernize_strpos' => false, // requires PHP 8 'protected_to_private' => false, - )) + ]) ->setRiskyAllowed(true) ; diff --git a/src/Cache.php b/src/Cache.php index f861e4d96..e733bc435 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -87,7 +87,7 @@ public function removeLegacyTags(array $data): array if (!$this->symfonyConstraints->matches($constraint)) { if (null !== $this->io) { - $this->io->writeError(sprintf('Restricting packages listed in "symfony/symfony" to "%s"', $this->symfonyRequire)); + $this->io->writeError(\sprintf('Restricting packages listed in "symfony/symfony" to "%s"', $this->symfonyRequire)); $this->io = null; } unset($versions[$version]); diff --git a/src/Command/DumpEnvCommand.php b/src/Command/DumpEnvCommand.php index 6f7ed6f1f..529bc9f0b 100644 --- a/src/Command/DumpEnvCommand.php +++ b/src/Command/DumpEnvCommand.php @@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function loadEnv(string $path, ?string $env, array $runtime): array { if (!file_exists($autoloadFile = $this->config->get('vendor-dir').'/autoload.php')) { - throw new \RuntimeException(sprintf('Please run "composer install" before running this command: "%s" not found.', $autoloadFile)); + throw new \RuntimeException(\sprintf('Please run "composer install" before running this command: "%s" not found.', $autoloadFile)); } require $autoloadFile; @@ -112,7 +112,7 @@ private function loadEnv(string $path, ?string $env, array $runtime): array } if (!$env) { - throw new \RuntimeException(sprintf('Please provide the name of the environment either by passing it as command line argument or by defining the "%s" variable in the ".env.local" file.', $envKey)); + throw new \RuntimeException(\sprintf('Please provide the name of the environment either by passing it as command line argument or by defining the "%s" variable in the ".env.local" file.', $envKey)); } $testEnvs = $runtime['test_envs'] ?? ['test']; diff --git a/src/Command/InstallRecipesCommand.php b/src/Command/InstallRecipesCommand.php index d1ae1a4b1..3aa9ceeb6 100644 --- a/src/Command/InstallRecipesCommand.php +++ b/src/Command/InstallRecipesCommand.php @@ -89,13 +89,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($targetPackages = $input->getArgument('packages')) { if ($invalidPackages = array_diff($targetPackages, $totalPackages)) { - $io->writeError(sprintf('Cannot update: some packages are not installed: %s', implode(', ', $invalidPackages))); + $io->writeError(\sprintf('Cannot update: some packages are not installed: %s', implode(', ', $invalidPackages))); return 1; } if ($packagesRequiringForce = array_diff($targetPackages, $packages)) { - $io->writeError(sprintf('Recipe(s) already installed for: %s', implode(', ', $packagesRequiringForce))); + $io->writeError(\sprintf('Recipe(s) already installed for: %s', implode(', ', $packagesRequiringForce))); $io->writeError('Re-run the command with --force to re-install the recipes.'); $io->writeError(''); } @@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $operations = []; foreach ($packages as $package) { if (null === $pkg = $installedRepo->findPackage($package, '*')) { - $io->writeError(sprintf('Package %s is not installed', $package)); + $io->writeError(\sprintf('Package %s is not installed', $package)); return 1; } @@ -129,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($createEnvLocal = $force && file_exists($dotenvPath) && file_exists($dotenvPath.'.dist') && !file_exists($dotenvPath.'.local')) { rename($dotenvPath, $dotenvPath.'.local'); $pipes = []; - proc_close(proc_open(sprintf('git mv %s %s > %s 2>&1 || %s %1$s %2$s', ProcessExecutor::escape($dotenvFile.'.dist'), ProcessExecutor::escape($dotenvFile), $win ? 'NUL' : '/dev/null', $win ? 'rename' : 'mv'), $pipes, $pipes, $this->rootDir)); + proc_close(proc_open(\sprintf('git mv %s %s > %s 2>&1 || %s %1$s %2$s', ProcessExecutor::escape($dotenvFile.'.dist'), ProcessExecutor::escape($dotenvFile), $win ? 'NUL' : '/dev/null', $win ? 'rename' : 'mv'), $pipes, $pipes, $this->rootDir)); if (file_exists($this->rootDir.'/phpunit.xml.dist')) { touch($dotenvPath.'.test'); } @@ -164,7 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($createEnvLocal) { $root = '.' !== $this->rootDir ? $this->rootDir.'/' : ''; $output[] = ' To revert the changes made to .env files, run'; - $output[] = sprintf(' git mv %s %s && %s %s %1$s', ProcessExecutor::escape($root.$dotenvFile), ProcessExecutor::escape($root.$dotenvFile.'.dist'), $win ? 'rename' : 'mv', ProcessExecutor::escape($root.$dotenvFile.'.local')); + $output[] = \sprintf(' git mv %s %s && %s %s %1$s', ProcessExecutor::escape($root.$dotenvFile), ProcessExecutor::escape($root.$dotenvFile.'.dist'), $win ? 'rename' : 'mv', ProcessExecutor::escape($root.$dotenvFile.'.local')); $output[] = ''; } diff --git a/src/Command/RecipesCommand.php b/src/Command/RecipesCommand.php index c9fc1aee0..5c9c2b8f4 100644 --- a/src/Command/RecipesCommand.php +++ b/src/Command/RecipesCommand.php @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $pkgVersion = $this->symfonyLock->get($name)['version']; $pkg = new Package($name, $pkgVersion, $pkgVersion); } elseif (!$pkg) { - $this->getIO()->writeError(sprintf('Package %s is not installed', $name)); + $this->getIO()->writeError(\sprintf('Package %s is not installed', $name)); continue; } @@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $hasOutdatedRecipes = true; - $write[] = sprintf(' * %s %s', $name, $additional); + $write[] = \sprintf(' * %s %s', $name, $additional); } // Nothing to display @@ -136,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->getIO()->write(array_merge([ '', ' ', - sprintf(' %s recipes. ', $outdated ? ' Outdated' : 'Available'), + \sprintf(' %s recipes. ', $outdated ? ' Outdated' : 'Available'), ' ', '', ], $write, [ @@ -200,7 +200,7 @@ private function displayPackageInformation(Recipe $recipe) $io->write('version : '.($lockVersion ?? 'n/a')); $io->write('status : '.$status); if (!$recipe->isAuto() && null !== $lockVersion) { - $recipeUrl = sprintf( + $recipeUrl = \sprintf( 'https://%s/tree/%s/%s/%s', $lockRepo, // if something fails, default to the branch as the closest "sha" @@ -217,7 +217,7 @@ private function displayPackageInformation(Recipe $recipe) } if ($lockRef !== $recipe->getRef() && null !== $lockVersion) { - $historyUrl = sprintf( + $historyUrl = \sprintf( 'https://%s/commits/%s/%s', $lockRepo, $lockBranch, @@ -249,7 +249,7 @@ private function displayPackageInformation(Recipe $recipe) $io->write([ '', 'Update this recipe by running:', - sprintf('composer recipes:update %s', $recipe->getName()), + \sprintf('composer recipes:update %s', $recipe->getName()), ]); } } @@ -292,7 +292,7 @@ private function displayFilesTree(array $tree) $treeBar = '└'; } - $info = sprintf( + $info = \sprintf( '%s──%s', $treeBar, $dir @@ -319,7 +319,7 @@ private function displayTree(array $tree, $previousTreeBar = '├', $level = 1) $treeBar = $previousTreeBar.' └'; } - $info = sprintf( + $info = \sprintf( '%s──%s', $treeBar, $dir diff --git a/src/Command/UnpackCommand.php b/src/Command/UnpackCommand.php index 4054f3016..cadd9ca0b 100644 --- a/src/Command/UnpackCommand.php +++ b/src/Command/UnpackCommand.php @@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $op = new Operation(true, $input->getOption('sort-packages') || $composer->getConfig()->get('sort-packages')); foreach ($versionParser->parseNameVersionPairs($packages) as $package) { if (null === $pkg = $installedRepo->findPackage($package['name'], '*')) { - $io->writeError(sprintf('Package %s is not installed', $package['name'])); + $io->writeError(\sprintf('Package %s is not installed', $package['name'])); return 1; } @@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->writeError('Unpacking Symfony packs'); foreach ($result->getUnpacked() as $pkg) { - $io->writeError(sprintf(' - Unpacked %s', $pkg->getName())); + $io->writeError(\sprintf(' - Unpacked %s', $pkg->getName())); } $unpacker->updateLock($result, $io); diff --git a/src/Command/UpdateRecipesCommand.php b/src/Command/UpdateRecipesCommand.php index 15296efc1..96d7d0d8f 100644 --- a/src/Command/UpdateRecipesCommand.php +++ b/src/Command/UpdateRecipesCommand.php @@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!$symfonyLock->has($packageName)) { $io->writeError([ 'Package not found inside symfony.lock. It looks like it\'s not installed?', - sprintf('Try running composer recipes:install %s --force -v to re-install the recipe.', $packageName), + \sprintf('Try running composer recipes:install %s --force -v to re-install the recipe.', $packageName), ]); return 1; @@ -104,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->writeError([ 'It doesn\'t look like this package had a recipe when it was originally installed.', 'To install the latest version of the recipe, if there is one, run:', - sprintf(' composer recipes:install %s --force -v', $packageName), + \sprintf(' composer recipes:install %s --force -v', $packageName), ]); return 1; @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'The version of the installed recipe was not saved into symfony.lock.', 'This is possible if it was installed by an old version of Symfony Flex.', 'Update the recipe by re-installing the latest version with:', - sprintf(' composer recipes:install %s --force -v', $packageName), + \sprintf(' composer recipes:install %s --force -v', $packageName), ]); return 1; @@ -131,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->writeError([ 'The original recipe version you have installed could not be found, it may be too old.', 'Update the recipe by re-installing the latest version with:', - sprintf(' composer recipes:install %s --force -v', $packageName), + \sprintf(' composer recipes:install %s --force -v', $packageName), ]); return 1; @@ -140,13 +140,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $newRecipe = $this->getRecipe($package); if ($newRecipe->getRef() === $originalRecipe->getRef()) { - $io->write(sprintf('This recipe for %s is already at the latest version.', $packageName)); + $io->write(\sprintf('This recipe for %s is already at the latest version.', $packageName)); return 0; } $io->write([ - sprintf(' Updating recipe for %s...', $packageName), + \sprintf(' Updating recipe for %s...', $packageName), '', ]); @@ -164,7 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $throwable->getMessage(), '', 'Update the recipe by re-installing the latest version with:', - sprintf(' composer recipes:install %s --force -v', $packageName), + \sprintf(' composer recipes:install %s --force -v', $packageName), ]); return 1; @@ -211,7 +211,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ' This recipe copies the following paths from the bundle into your app:', ]); foreach ($recipeUpdate->getCopyFromPackagePaths() as $source => $target) { - $io->write(sprintf(' * %s => %s', $source, $target)); + $io->write(\sprintf(' * %s => %s', $source, $target)); } $io->write([ '', @@ -223,12 +223,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (0 !== \count($patch->getRemovedPatches())) { if (1 === \count($patch->getRemovedPatches())) { $notes = [ - sprintf(' The file %s was not updated because it doesn\'t exist in your app.', array_keys($patch->getRemovedPatches())[0]), + \sprintf(' The file %s was not updated because it doesn\'t exist in your app.', array_keys($patch->getRemovedPatches())[0]), ]; } else { $notes = [' The following files were not updated because they don\'t exist in your app:']; foreach ($patch->getRemovedPatches() as $filename => $contents) { - $notes[] = sprintf(' * %s', $filename); + $notes[] = \sprintf(' * %s', $filename); } } $io->write([ @@ -242,7 +242,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int file_put_contents($this->rootDir.'/'.$patchFilename, implode("\n", $patch->getRemovedPatches())); $io->write([ '', - sprintf(' Saved diff to %s', $patchFilename), + \sprintf(' Saved diff to %s', $patchFilename), ]); } } @@ -347,7 +347,7 @@ private function generateChangelog(Recipe $originalRecipe): ?array if ($handlesHrefGracefully) { $url = "\033]8;;$url\033\\$number\033]8;;\033\\"; } - $lines[] = sprintf(' * %s (PR %s)', $data['title'], $url); + $lines[] = \sprintf(' * %s (PR %s)', $data['title'], $url); } return $lines; diff --git a/src/Configurator.php b/src/Configurator.php index 56976823b..444abb86a 100644 --- a/src/Configurator.php +++ b/src/Configurator.php @@ -104,7 +104,7 @@ public function unconfigure(Recipe $recipe, Lock $lock) private function get($key): AbstractConfigurator { if (!isset($this->configurators[$key]) && !isset($this->postInstallConfigurators[$key])) { - throw new \InvalidArgumentException(sprintf('Unknown configurator "%s".', $key)); + throw new \InvalidArgumentException(\sprintf('Unknown configurator "%s".', $key)); } if (isset($this->cache[$key])) { diff --git a/src/Configurator/AbstractConfigurator.php b/src/Configurator/AbstractConfigurator.php index aea4dda94..7608cab22 100644 --- a/src/Configurator/AbstractConfigurator.php +++ b/src/Configurator/AbstractConfigurator.php @@ -56,22 +56,22 @@ protected function write($messages, $verbosity = IOInterface::VERBOSE) protected function isFileMarked(Recipe $recipe, string $file): bool { - return is_file($file) && false !== strpos(file_get_contents($file), sprintf('###> %s ###', $recipe->getName())); + return is_file($file) && false !== strpos(file_get_contents($file), \sprintf('###> %s ###', $recipe->getName())); } protected function markData(Recipe $recipe, string $data): string { - return "\n".sprintf('###> %s ###%s%s%s###< %s ###%s', $recipe->getName(), "\n", rtrim($data, "\r\n"), "\n", $recipe->getName(), "\n"); + return "\n".\sprintf('###> %s ###%s%s%s###< %s ###%s', $recipe->getName(), "\n", rtrim($data, "\r\n"), "\n", $recipe->getName(), "\n"); } protected function isFileXmlMarked(Recipe $recipe, string $file): bool { - return is_file($file) && false !== strpos(file_get_contents($file), sprintf('###+ %s ###', $recipe->getName())); + return is_file($file) && false !== strpos(file_get_contents($file), \sprintf('###+ %s ###', $recipe->getName())); } protected function markXmlData(Recipe $recipe, string $data): string { - return "\n".sprintf(' %s%s%s %s', $recipe->getName(), "\n", rtrim($data, "\r\n"), "\n", $recipe->getName(), "\n"); + return "\n".\sprintf(' %s%s%s %s', $recipe->getName(), "\n", rtrim($data, "\r\n"), "\n", $recipe->getName(), "\n"); } /** diff --git a/src/Configurator/AddLinesConfigurator.php b/src/Configurator/AddLinesConfigurator.php index 146b28b54..8a4bc6d62 100644 --- a/src/Configurator/AddLinesConfigurator.php +++ b/src/Configurator/AddLinesConfigurator.php @@ -38,7 +38,7 @@ public function configure(Recipe $recipe, $config, Lock $lock, array $options = $this->executeConfigure($recipe, $config); foreach ($this->fileContents as $file => $contents) { - $this->write(sprintf('[add-lines] Patching file "%s"', $this->relativize($file))); + $this->write(\sprintf('[add-lines] Patching file "%s"', $this->relativize($file))); file_put_contents($file, $contents); } } @@ -49,7 +49,7 @@ public function unconfigure(Recipe $recipe, $config, Lock $lock): void $this->executeUnconfigure($recipe, $config); foreach ($this->fileContents as $file => $change) { - $this->write(sprintf('[add-lines] Reverting file "%s"', $this->relativize($file))); + $this->write(\sprintf('[add-lines] Reverting file "%s"', $this->relativize($file))); file_put_contents($file, $change); } } @@ -81,7 +81,7 @@ public function executeConfigure(Recipe $recipe, $config): void { foreach ($config as $patch) { if (!isset($patch['file'])) { - $this->write(sprintf('The "file" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); + $this->write(\sprintf('The "file" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); continue; } @@ -91,7 +91,7 @@ public function executeConfigure(Recipe $recipe, $config): void } if (!isset($patch['content'])) { - $this->write(sprintf('The "content" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); + $this->write(\sprintf('The "content" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); continue; } @@ -101,7 +101,7 @@ public function executeConfigure(Recipe $recipe, $config): void $warnIfMissing = isset($patch['warn_if_missing']) && $patch['warn_if_missing']; if (!is_file($file)) { $this->write([ - sprintf('Could not add lines to file %s as it does not exist. Missing lines:', $patch['file']), + \sprintf('Could not add lines to file %s as it does not exist. Missing lines:', $patch['file']), '"""', $content, '"""', @@ -112,19 +112,19 @@ public function executeConfigure(Recipe $recipe, $config): void } if (!isset($patch['position'])) { - $this->write(sprintf('The "position" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); + $this->write(\sprintf('The "position" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); continue; } $position = $patch['position']; if (!\in_array($position, self::VALID_POSITIONS, true)) { - $this->write(sprintf('The "position" key must be one of "%s" for the "add-lines" configurator for recipe "%s". Skipping', implode('", "', self::VALID_POSITIONS), $recipe->getName())); + $this->write(\sprintf('The "position" key must be one of "%s" for the "add-lines" configurator for recipe "%s". Skipping', implode('", "', self::VALID_POSITIONS), $recipe->getName())); continue; } if (self::POSITION_AFTER_TARGET === $position && !isset($patch['target'])) { - $this->write(sprintf('The "target" key is required when "position" is "%s" for the "add-lines" configurator for recipe "%s". Skipping', self::POSITION_AFTER_TARGET, $recipe->getName())); + $this->write(\sprintf('The "target" key is required when "position" is "%s" for the "add-lines" configurator for recipe "%s". Skipping', self::POSITION_AFTER_TARGET, $recipe->getName())); continue; } @@ -139,7 +139,7 @@ public function executeUnconfigure(Recipe $recipe, $config): void { foreach ($config as $patch) { if (!isset($patch['file'])) { - $this->write(sprintf('The "file" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); + $this->write(\sprintf('The "file" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); continue; } @@ -153,7 +153,7 @@ public function executeUnconfigure(Recipe $recipe, $config): void } if (!isset($patch['content'])) { - $this->write(sprintf('The "content" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); + $this->write(\sprintf('The "content" key is required for the "add-lines" configurator for recipe "%s". Skipping', $recipe->getName())); continue; } @@ -196,7 +196,7 @@ private function getPatchedContents(string $file, string $value, string $positio if (!$targetFound) { $this->write([ - sprintf('Could not add lines after "%s" as no such string was found in "%s". Missing lines:', $target, $file), + \sprintf('Could not add lines after "%s" as no such string was found in "%s". Missing lines:', $target, $file), '"""', $value, '"""', @@ -221,7 +221,7 @@ private function getUnPatchedContents(string $file, $value): string if (false !== strpos($fileContents, "\n".$value)) { $value = "\n".$value; } elseif (false !== strpos($fileContents, $value."\n")) { - $value = $value."\n"; + $value .= "\n"; } $position = strpos($fileContents, $value); diff --git a/src/Configurator/ContainerConfigurator.php b/src/Configurator/ContainerConfigurator.php index e501a09d0..4fd9e89d2 100644 --- a/src/Configurator/ContainerConfigurator.php +++ b/src/Configurator/ContainerConfigurator.php @@ -84,7 +84,7 @@ private function configureParameters(array $parameters, bool $update = false): s } foreach ($parameters as $key => $value) { $matches = []; - if (preg_match(sprintf('/^\s+%s\:/', preg_quote($key, '/')), $line, $matches)) { + if (preg_match(\sprintf('/^\s+%s\:/', preg_quote($key, '/')), $line, $matches)) { if ($update) { $lines[$i] = substr($line, 0, \strlen($matches[0])).' '.str_replace("'", "''", $value)."\n"; } @@ -101,10 +101,10 @@ private function configureParameters(array $parameters, bool $update = false): s } foreach ($parameters as $key => $value) { if (\is_array($value)) { - $parametersLines[] = sprintf(" %s:\n%s", $key, $this->dumpYaml(2, $value)); + $parametersLines[] = \sprintf(" %s:\n%s", $key, $this->dumpYaml(2, $value)); continue; } - $parametersLines[] = sprintf(" %s: '%s'%s", $key, str_replace("'", "''", $value), "\n"); + $parametersLines[] = \sprintf(" %s: '%s'%s", $key, str_replace("'", "''", $value), "\n"); } if (!$endAt) { $parametersLines[] = "\n"; @@ -134,7 +134,7 @@ private function removeParameters($level, $params, $line) if (\is_array($value) && $this->removeParameters($level + 1, $value, $line)) { return true; } - if (preg_match(sprintf('/^(\s{%d}|\t{%d})+%s\:/', 4 * $level, $level, preg_quote($key, '/')), $line)) { + if (preg_match(\sprintf('/^(\s{%d}|\t{%d})+%s\:/', 4 * $level, $level, preg_quote($key, '/')), $line)) { return true; } } @@ -148,10 +148,10 @@ private function dumpYaml($level, $array): string foreach ($array as $key => $value) { $line .= str_repeat(' ', $level); if (!\is_array($value)) { - $line .= sprintf("%s: '%s'\n", $key, str_replace("'", "''", $value)); + $line .= \sprintf("%s: '%s'\n", $key, str_replace("'", "''", $value)); continue; } - $line .= sprintf("%s:\n", $key).$this->dumpYaml($level + 1, $value); + $line .= \sprintf("%s:\n", $key).$this->dumpYaml($level + 1, $value); } return $line; diff --git a/src/Configurator/CopyFromPackageConfigurator.php b/src/Configurator/CopyFromPackageConfigurator.php index 9d28fa236..3ae514871 100644 --- a/src/Configurator/CopyFromPackageConfigurator.php +++ b/src/Configurator/CopyFromPackageConfigurator.php @@ -59,7 +59,7 @@ public function update(RecipeUpdate $recipeUpdate, array $originalConfig, array // any remaining files are new, and we can copy them foreach ($this->getFilesToCopy($newConfig, $packageDir) as $source => $target) { if (!file_exists($source)) { - throw new \LogicException(sprintf('File "%s" does not exist!', $source)); + throw new \LogicException(\sprintf('File "%s" does not exist!', $source)); } $recipeUpdate->setNewFile($target, file_get_contents($source)); @@ -93,7 +93,7 @@ private function removeFiles(array $manifest, string $from, string $to) $targetPath = $this->path->concatenate([$to, $target]); if (file_exists($targetPath)) { @unlink($targetPath); - $this->write(sprintf(' Removed "%s"', $this->path->relativize($targetPath))); + $this->write(\sprintf(' Removed "%s"', $this->path->relativize($targetPath))); } } } @@ -130,17 +130,17 @@ public function copyFile(string $source, string $target, array $options) } if (!file_exists($source)) { - throw new \LogicException(sprintf('File "%s" does not exist!', $source)); + throw new \LogicException(\sprintf('File "%s" does not exist!', $source)); } if (!file_exists(\dirname($target))) { mkdir(\dirname($target), 0777, true); - $this->write(sprintf(' Created "%s"', $this->path->relativize(\dirname($target)))); + $this->write(\sprintf(' Created "%s"', $this->path->relativize(\dirname($target)))); } file_put_contents($target, $this->options->expandTargetDir(file_get_contents($source))); @chmod($target, fileperms($target) | (fileperms($source) & 0111)); - $this->write(sprintf(' Created "%s"', $this->path->relativize($target))); + $this->write(\sprintf(' Created "%s"', $this->path->relativize($target))); } private function removeFilesFromDir(string $source, string $target) @@ -154,10 +154,10 @@ private function removeFilesFromDir(string $source, string $target) if ($item->isDir()) { // that removes the dir only if it is empty @rmdir($targetPath); - $this->write(sprintf(' Removed directory "%s"', $this->path->relativize($targetPath))); + $this->write(\sprintf(' Removed directory "%s"', $this->path->relativize($targetPath))); } else { @unlink($targetPath); - $this->write(sprintf(' Removed "%s"', $this->path->relativize($targetPath))); + $this->write(\sprintf(' Removed "%s"', $this->path->relativize($targetPath))); } } } diff --git a/src/Configurator/CopyFromRecipeConfigurator.php b/src/Configurator/CopyFromRecipeConfigurator.php index b4233111e..7a99a6dfc 100644 --- a/src/Configurator/CopyFromRecipeConfigurator.php +++ b/src/Configurator/CopyFromRecipeConfigurator.php @@ -127,7 +127,7 @@ private function copyFile(string $to, string $contents, bool $executable, array @chmod($to, fileperms($to) | 0111); } - $this->write(sprintf(' Created "%s"', $this->path->relativize($to))); + $this->write(\sprintf(' Created "%s"', $this->path->relativize($to))); return $copiedFile; } @@ -161,7 +161,7 @@ private function removeFile(string $to) } @unlink($to); - $this->write(sprintf(' Removed "%s"', $this->path->relativize($to))); + $this->write(\sprintf(' Removed "%s"', $this->path->relativize($to))); if (0 === \count(glob(\dirname($to).'/*', \GLOB_NOSORT))) { @rmdir(\dirname($to)); diff --git a/src/Configurator/DockerComposeConfigurator.php b/src/Configurator/DockerComposeConfigurator.php index 99e6460ff..0f942c7b5 100644 --- a/src/Configurator/DockerComposeConfigurator.php +++ b/src/Configurator/DockerComposeConfigurator.php @@ -31,7 +31,7 @@ class DockerComposeConfigurator extends AbstractConfigurator { private $filesystem; - public static $configureDockerRecipes = null; + public static $configureDockerRecipes; public function __construct(Composer $composer, IOInterface $io, Options $options) { @@ -61,18 +61,18 @@ public function unconfigure(Recipe $recipe, $config, Lock $lock) $name = $recipe->getName(); // Remove recipe and add break line - $contents = preg_replace(sprintf('{%s+###> %s ###.*?###< %s ###%s+}s', "\n", $name, $name, "\n"), \PHP_EOL.\PHP_EOL, file_get_contents($dockerComposeFile), -1, $count); + $contents = preg_replace(\sprintf('{%s+###> %s ###.*?###< %s ###%s+}s', "\n", $name, $name, "\n"), \PHP_EOL.\PHP_EOL, file_get_contents($dockerComposeFile), -1, $count); if (!$count) { return; } foreach ($extra as $key => $value) { - if (0 === preg_match(sprintf('{^%s:[ \t\r\n]*([ \t]+\w|#)}m', $key), $contents, $matches)) { - $contents = preg_replace(sprintf('{\n?^%s:[ \t\r\n]*}sm', $key), '', $contents, -1, $count); + if (0 === preg_match(\sprintf('{^%s:[ \t\r\n]*([ \t]+\w|#)}m', $key), $contents, $matches)) { + $contents = preg_replace(\sprintf('{\n?^%s:[ \t\r\n]*}sm', $key), '', $contents, -1, $count); } } - $this->write(sprintf('Removing Docker Compose entries from "%s"', $dockerComposeFile)); + $this->write(\sprintf('Removing Docker Compose entries from "%s"', $dockerComposeFile)); file_put_contents($dockerComposeFile, ltrim($contents, "\n")); } @@ -181,7 +181,7 @@ private function findDockerComposeFile(string $rootDir, string $file): ?string } if (!$this->filesystem->isAbsolutePath($f)) { - $f = realpath(sprintf('%s/%s', $rootDir, $f)); + $f = realpath(\sprintf('%s/%s', $rootDir, $f)); } if ($this->filesystem->exists($f)) { @@ -194,12 +194,12 @@ private function findDockerComposeFile(string $rootDir, string $file): ?string $dir = $rootDir; do { if ( - $this->filesystem->exists($dockerComposeFile = sprintf('%s/%s', $dir, $file)) || + $this->filesystem->exists($dockerComposeFile = \sprintf('%s/%s', $dir, $file)) // Test with the ".yml" extension if the file doesn't end up with ".yaml" - $this->filesystem->exists($dockerComposeFile = substr($dockerComposeFile, 0, -3).'ml') || + || $this->filesystem->exists($dockerComposeFile = substr($dockerComposeFile, 0, -3).'ml') // Test with the legacy "docker-" suffix if "compose.ya?ml" doesn't exist - $this->filesystem->exists($dockerComposeFile = sprintf('%s/docker-%s', $dir, $file)) || - $this->filesystem->exists($dockerComposeFile = substr($dockerComposeFile, 0, -3).'ml') + || $this->filesystem->exists($dockerComposeFile = \sprintf('%s/docker-%s', $dir, $file)) + || $this->filesystem->exists($dockerComposeFile = substr($dockerComposeFile, 0, -3).'ml') ) { return $dockerComposeFile; } @@ -218,12 +218,12 @@ private function parse($level, $indent, $services): string $line .= str_repeat(' ', $indent * $level); if (!\is_array($value)) { if (\is_string($key)) { - $line .= sprintf('%s:', $key); + $line .= \sprintf('%s:', $key); } - $line .= sprintf("%s\n", $value); + $line .= \sprintf("%s\n", $value); continue; } - $line .= sprintf("%s:\n", $key).$this->parse($level + 1, $indent, $value); + $line .= \sprintf("%s:\n", $key).$this->parse($level + 1, $indent, $value); } return $line; @@ -237,14 +237,14 @@ private function configureDockerCompose(Recipe $recipe, array $config, bool $upd if (null === $dockerComposeFile) { $dockerComposeFile = $rootDir.'/'.$file; file_put_contents($dockerComposeFile, ''); - $this->write(sprintf(' Created "%s"', $file)); + $this->write(\sprintf(' Created "%s"', $file)); } if (!$update && $this->isFileMarked($recipe, $dockerComposeFile)) { continue; } - $this->write(sprintf('Adding Docker Compose definitions to "%s"', $dockerComposeFile)); + $this->write(\sprintf('Adding Docker Compose definitions to "%s"', $dockerComposeFile)); $offset = 2; $node = null; @@ -317,7 +317,7 @@ private function configureDockerCompose(Recipe $recipe, array $config, bool $upd continue; } - $lines[] = sprintf("\n%s:", $key); + $lines[] = \sprintf("\n%s:", $key); $lines[] = $this->markData($recipe, $this->parse(1, $offset, $value)); } @@ -372,7 +372,7 @@ private function getContentsAfterApplyingRecipe(string $rootDir, Recipe $recipe, private static function askDockerSupport(IOInterface $io, Recipe $recipe): string { $warning = $io->isInteractive() ? 'WARNING' : 'IGNORING'; - $io->writeError(sprintf(' - %s %s', $warning, $recipe->getFormattedOrigin())); + $io->writeError(\sprintf(' - %s %s', $warning, $recipe->getFormattedOrigin())); $question = ' The recipe for this package contains some Docker configuration. This may create/update compose.yaml or update Dockerfile (if it exists). diff --git a/src/Configurator/DockerfileConfigurator.php b/src/Configurator/DockerfileConfigurator.php index 423cf9cff..902a768c1 100644 --- a/src/Configurator/DockerfileConfigurator.php +++ b/src/Configurator/DockerfileConfigurator.php @@ -38,7 +38,7 @@ public function unconfigure(Recipe $recipe, $config, Lock $lock) } $name = $recipe->getName(); - $contents = preg_replace(sprintf('{%s+###> %s ###.*?###< %s ###%s+}s', "\n", $name, $name, "\n"), "\n", file_get_contents($dockerfile), -1, $count); + $contents = preg_replace(\sprintf('{%s+###> %s ###.*?###< %s ###%s+}s', "\n", $name, $name, "\n"), "\n", file_get_contents($dockerfile), -1, $count); if (!$count) { return; } diff --git a/src/Configurator/EnvConfigurator.php b/src/Configurator/EnvConfigurator.php index 97c62d6f0..447e67012 100644 --- a/src/Configurator/EnvConfigurator.php +++ b/src/Configurator/EnvConfigurator.php @@ -143,12 +143,12 @@ private function unconfigureEnvFiles(Recipe $recipe, $vars) continue; } - $contents = preg_replace(sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $recipe->getName(), $recipe->getName(), "\n"), "\n", file_get_contents($env), -1, $count); + $contents = preg_replace(\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $recipe->getName(), $recipe->getName(), "\n"), "\n", file_get_contents($env), -1, $count); if (!$count) { continue; } - $this->write(sprintf('Removing environment variables from %s', $file)); + $this->write(\sprintf('Removing environment variables from %s', $file)); file_put_contents($env, $contents); } } @@ -161,12 +161,12 @@ private function unconfigurePhpUnit(Recipe $recipe, $vars) continue; } - $contents = preg_replace(sprintf('{%s*\s+.*%s+}s', "\n", $recipe->getName(), $recipe->getName(), "\n"), "\n", file_get_contents($phpunit), -1, $count); + $contents = preg_replace(\sprintf('{%s*\s+.*%s+}s', "\n", $recipe->getName(), $recipe->getName(), "\n"), "\n", file_get_contents($phpunit), -1, $count); if (!$count) { continue; } - $this->write(sprintf('Removing environment variables from %s', $file)); + $this->write(\sprintf('Removing environment variables from %s', $file)); file_put_contents($phpunit, $contents); } } @@ -265,7 +265,7 @@ private function findExistingValue(string $var, string $filename, Recipe $recipe $lines = explode("\n", $section); foreach ($lines as $line) { - if (0 !== strpos($line, sprintf('%s=', $var))) { + if (0 !== strpos($line, \sprintf('%s=', $var))) { continue; } diff --git a/src/Configurator/GitignoreConfigurator.php b/src/Configurator/GitignoreConfigurator.php index 9d33d6c15..7241ba284 100644 --- a/src/Configurator/GitignoreConfigurator.php +++ b/src/Configurator/GitignoreConfigurator.php @@ -34,7 +34,7 @@ public function unconfigure(Recipe $recipe, $vars, Lock $lock) return; } - $contents = preg_replace(sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $recipe->getName(), $recipe->getName(), "\n"), "\n", file_get_contents($file), -1, $count); + $contents = preg_replace(\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $recipe->getName(), $recipe->getName(), "\n"), "\n", file_get_contents($file), -1, $count); if (!$count) { return; } diff --git a/src/Configurator/MakefileConfigurator.php b/src/Configurator/MakefileConfigurator.php index 5b5abe437..b8b061aff 100644 --- a/src/Configurator/MakefileConfigurator.php +++ b/src/Configurator/MakefileConfigurator.php @@ -33,12 +33,12 @@ public function unconfigure(Recipe $recipe, $vars, Lock $lock) return; } - $contents = preg_replace(sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $recipe->getName(), $recipe->getName(), "\n"), "\n", file_get_contents($makefile), -1, $count); + $contents = preg_replace(\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $recipe->getName(), $recipe->getName(), "\n"), "\n", file_get_contents($makefile), -1, $count); if (!$count) { return; } - $this->write(sprintf('Removing Makefile entries from %s', $makefile)); + $this->write(\sprintf('Removing Makefile entries from %s', $makefile)); if (!trim($contents)) { @unlink($makefile); } else { diff --git a/src/CurlDownloader.php b/src/CurlDownloader.php index 9da133311..fb91fabbd 100644 --- a/src/CurlDownloader.php +++ b/src/CurlDownloader.php @@ -46,7 +46,7 @@ class CurlDownloader public function __construct() { $this->multiHandle = $mh = curl_multi_init(); - curl_multi_setopt($mh, \CURLMOPT_PIPELINING, /*CURLPIPE_MULTIPLEX*/ 2); + curl_multi_setopt($mh, \CURLMOPT_PIPELINING, /* CURLPIPE_MULTIPLEX */ 2); if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) { curl_multi_setopt($mh, \CURLMOPT_MAX_HOST_CONNECTIONS, 8); } diff --git a/src/Downloader.php b/src/Downloader.php index 2cdf74682..5d83e3eab 100644 --- a/src/Downloader.php +++ b/src/Downloader.php @@ -182,17 +182,17 @@ public function getRecipes(array $operations): array if (0 === strpos($version, 'dev-') && isset($package->getExtra()['branch-alias'])) { $branchAliases = $package->getExtra()['branch-alias']; if ( - (isset($branchAliases[$version]) && $alias = $branchAliases[$version]) || - (isset($branchAliases['dev-main']) && $alias = $branchAliases['dev-main']) || - (isset($branchAliases['dev-trunk']) && $alias = $branchAliases['dev-trunk']) || - (isset($branchAliases['dev-develop']) && $alias = $branchAliases['dev-develop']) || - (isset($branchAliases['dev-default']) && $alias = $branchAliases['dev-default']) || - (isset($branchAliases['dev-latest']) && $alias = $branchAliases['dev-latest']) || - (isset($branchAliases['dev-next']) && $alias = $branchAliases['dev-next']) || - (isset($branchAliases['dev-current']) && $alias = $branchAliases['dev-current']) || - (isset($branchAliases['dev-support']) && $alias = $branchAliases['dev-support']) || - (isset($branchAliases['dev-tip']) && $alias = $branchAliases['dev-tip']) || - (isset($branchAliases['dev-master']) && $alias = $branchAliases['dev-master']) + (isset($branchAliases[$version]) && $alias = $branchAliases[$version]) + || (isset($branchAliases['dev-main']) && $alias = $branchAliases['dev-main']) + || (isset($branchAliases['dev-trunk']) && $alias = $branchAliases['dev-trunk']) + || (isset($branchAliases['dev-develop']) && $alias = $branchAliases['dev-develop']) + || (isset($branchAliases['dev-default']) && $alias = $branchAliases['dev-default']) + || (isset($branchAliases['dev-latest']) && $alias = $branchAliases['dev-latest']) + || (isset($branchAliases['dev-next']) && $alias = $branchAliases['dev-next']) + || (isset($branchAliases['dev-current']) && $alias = $branchAliases['dev-current']) + || (isset($branchAliases['dev-support']) && $alias = $branchAliases['dev-support']) + || (isset($branchAliases['dev-tip']) && $alias = $branchAliases['dev-tip']) + || (isset($branchAliases['dev-master']) && $alias = $branchAliases['dev-master']) ) { $version = $alias; } @@ -250,7 +250,7 @@ public function getRecipes(array $operations): array // FIXME: Multi name with getNames() $name = str_replace('/', ',', $package->getName()); - $path = sprintf('%s,%s%s', $name, $o, $version); + $path = \sprintf('%s,%s%s', $name, $o, $version); if ($date = $package->getReleaseDate()) { $path .= ','.$date->format('U'); } diff --git a/src/Flex.php b/src/Flex.php index 30be50649..3d4bff9f8 100644 --- a/src/Flex.php +++ b/src/Flex.php @@ -229,9 +229,9 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__) $resolver = new PackageResolver($this->downloader); if (version_compare('1.1.0', PluginInterface::PLUGIN_API_VERSION, '>')) { - $note = $app->has('self-update') ? sprintf('`php %s self-update`', $_SERVER['argv'][0]) : 'https://getcomposer.org/'; + $note = $app->has('self-update') ? \sprintf('`php %s self-update`', $_SERVER['argv'][0]) : 'https://getcomposer.org/'; $io->writeError('Some Symfony Flex features may not work as expected: your version of Composer is too old'); - $io->writeError(sprintf('Please upgrade using %s', $note)); + $io->writeError(\sprintf('Please upgrade using %s', $note)); } try { @@ -472,7 +472,7 @@ public function install(Event $event) $this->io->writeError(''); $this->io->writeError('What about running composer global require symfony/thanks && composer thanks now?'); - $this->io->writeError(sprintf('This will spread some %s by sending a %s to the GitHub repositories of your fellow package maintainers.', $love, $star)); + $this->io->writeError(\sprintf('This will spread some %s by sending a %s to the GitHub repositories of your fellow package maintainers.', $love, $star)); } $this->io->writeError(''); @@ -490,7 +490,7 @@ public function install(Event $event) return; } - $this->io->writeError(sprintf('Symfony operations: %d recipe%s (%s)', \count($recipes), \count($recipes) > 1 ? 's' : '', $this->downloader->getSessionId())); + $this->io->writeError(\sprintf('Symfony operations: %d recipe%s (%s)', \count($recipes), \count($recipes) > 1 ? 's' : '', $this->downloader->getSessionId())); $installContribs = $this->composer->getPackage()->getExtra()['symfony']['allow-contrib'] ?? false; $manifest = null; $originalComposerJsonHash = $this->getComposerJsonHash(); @@ -498,8 +498,8 @@ public function install(Event $event) foreach ($recipes as $recipe) { if ('install' === $recipe->getJob() && !$installContribs && $recipe->isContrib()) { $warning = $this->io->isInteractive() ? 'WARNING' : 'IGNORING'; - $this->io->writeError(sprintf(' - %s %s', $warning, $this->formatOrigin($recipe))); - $question = sprintf(' The recipe for this package comes from the "contrib" repository, which is open to community contributions. + $this->io->writeError(\sprintf(' - %s %s', $warning, $this->formatOrigin($recipe))); + $question = \sprintf(' The recipe for this package comes from the "contrib" repository, which is open to community contributions. Review the recipe at %s Do you want to execute this recipe? @@ -542,13 +542,13 @@ function ($value) { switch ($recipe->getJob()) { case 'install': $postInstallRecipes[] = $recipe; - $this->io->writeError(sprintf(' - Configuring %s', $this->formatOrigin($recipe))); + $this->io->writeError(\sprintf(' - Configuring %s', $this->formatOrigin($recipe))); $this->configurator->install($recipe, $this->lock, [ 'force' => $event instanceof UpdateEvent && $event->force(), ]); $manifest = $recipe->getManifest(); if (isset($manifest['post-install-output'])) { - $this->postInstallOutput[] = sprintf(' %s instructions:', $recipe->getName()); + $this->postInstallOutput[] = \sprintf(' %s instructions:', $recipe->getName()); $this->postInstallOutput[] = ''; foreach ($manifest['post-install-output'] as $line) { $this->postInstallOutput[] = $this->options->expandTargetDir($line); @@ -559,7 +559,7 @@ function ($value) { case 'update': break; case 'uninstall': - $this->io->writeError(sprintf(' - Unconfiguring %s', $this->formatOrigin($recipe))); + $this->io->writeError(\sprintf(' - Unconfiguring %s', $this->formatOrigin($recipe))); $this->configurator->unconfigure($recipe, $this->lock); break; } @@ -749,7 +749,7 @@ public function populateFilesCacheDir(InstallerEvent $event) } if (preg_match('#^https://github\.com/#', $package->getSourceUrl()) && preg_match('#^https://api\.github\.com/repos(/[^/]++/[^/]++/)zipball(.++)$#', $fileUrl, $m)) { - $fileUrl = sprintf('https://codeload.github.com%slegacy.zip%s', $m[1], $m[2]); + $fileUrl = \sprintf('https://codeload.github.com%slegacy.zip%s', $m[1], $m[2]); } $downloads[] = [$originUrl, $fileUrl, [], $file, false]; @@ -802,7 +802,7 @@ public function fetchRecipes(array $operations, bool $reset): array $job = method_exists($operation, 'getOperationType') ? $operation->getOperationType() : $operation->getJobType(); if (!isset($manifests[$name]) && isset($data['conflicts'][$name])) { - $this->io->writeError(sprintf(' - Skipping recipe for %s: all versions of the recipe conflict with your package versions.', $name)); + $this->io->writeError(\sprintf(' - Skipping recipe for %s: all versions of the recipe conflict with your package versions.', $name)); continue; } @@ -813,7 +813,7 @@ public function fetchRecipes(array $operations, bool $reset): array if (!isset($newManifests[$name])) { // no older recipe found - $this->io->writeError(sprintf(' - Skipping recipe for %s: all versions of the recipe conflict with your package versions.', $name)); + $this->io->writeError(\sprintf(' - Skipping recipe for %s: all versions of the recipe conflict with your package versions.', $name)); continue 2; } @@ -862,7 +862,7 @@ public function fetchRecipes(array $operations, bool $reset): array if ($bundles) { $manifest = [ - 'origin' => sprintf('%s:%s@auto-generated recipe', $name, $package->getPrettyVersion()), + 'origin' => \sprintf('%s:%s@auto-generated recipe', $name, $package->getPrettyVersion()), 'manifest' => ['bundles' => $bundles], ]; $recipes[$name] = new Recipe($package, $name, $job, $manifest); @@ -935,7 +935,7 @@ private function formatOrigin(Recipe $recipe): string return $origin; } - return sprintf('%s (>=%s): From %s', $matches[1], $matches[2], 'auto-generated recipe' === $matches[3] ? ''.$matches[3].'' : $matches[3]); + return \sprintf('%s (>=%s): From %s', $matches[1], $matches[2], 'auto-generated recipe' === $matches[3] ? ''.$matches[3].'' : $matches[3]); } private function shouldRecordOperation(OperationInterface $operation, bool $isDevMode, ?Composer $composer = null): bool @@ -1033,7 +1033,7 @@ private function unpack(Event $event) $this->io->writeError('Unpacking Symfony packs'); foreach ($result->getUnpacked() as $pkg) { - $this->io->writeError(sprintf(' - Unpacked %s', $pkg->getName())); + $this->io->writeError(\sprintf(' - Unpacked %s', $pkg->getName())); } $unpacker->updateLock($result, $this->io); diff --git a/src/GithubApi.php b/src/GithubApi.php index 1cfe0a9de..9290099c7 100644 --- a/src/GithubApi.php +++ b/src/GithubApi.php @@ -40,8 +40,8 @@ public function findRecipeCommitDataFromTreeRef(string $package, string $repo, s return null; } - $recipePath = sprintf('%s/%s', $package, $version); - $commitsData = $this->requestGitHubApi(sprintf( + $recipePath = \sprintf('%s/%s', $package, $version); + $commitsData = $this->requestGitHubApi(\sprintf( 'https://api.github.com/repos/%s/commits?path=%s&sha=%s', $repositoryName, $recipePath, @@ -85,7 +85,7 @@ public function getVersionsOfRecipe(string $repo, string $branch, string $recipe return null; } - $url = sprintf( + $url = \sprintf( 'https://api.github.com/repos/%s/contents/%s?ref=%s', $repositoryName, $recipePath, @@ -111,7 +111,7 @@ public function getCommitDataForPath(string $repo, string $path, string $branch) return []; } - $commitsData = $this->requestGitHubApi(sprintf( + $commitsData = $this->requestGitHubApi(\sprintf( 'https://api.github.com/repos/%s/commits?path=%s&sha=%s', $repositoryName, $path, @@ -142,7 +142,7 @@ public function getPullRequestForCommit(string $commit, string $repo): ?array $bestItem = null; foreach ($data['items'] as $item) { // make sure the PR referenced isn't from a different repository - if (false === strpos($item['html_url'], sprintf('%s/pull', $repositoryName))) { + if (false === strpos($item['html_url'], \sprintf('%s/pull', $repositoryName))) { continue; } diff --git a/src/InformationOperation.php b/src/InformationOperation.php index 8cad6a863..dd4a33aba 100644 --- a/src/InformationOperation.php +++ b/src/InformationOperation.php @@ -11,8 +11,8 @@ class InformationOperation implements OperationInterface { private $package; - private $recipeRef = null; - private $version = null; + private $recipeRef; + private $version; public function __construct(PackageInterface $package) { @@ -56,8 +56,6 @@ public function getJobType() } /** - * {@inheritdoc} - * * @return string */ public function getOperationType() @@ -66,8 +64,6 @@ public function getOperationType() } /** - * {@inheritdoc} - * * @return string */ public function show($lock) @@ -77,9 +73,6 @@ public function show($lock) return 'Information '.$this->package->getPrettyName().' ('.$pretty.')'; } - /** - * {@inheritdoc} - */ public function __toString() { return $this->show(false); diff --git a/src/Options.php b/src/Options.php index 3e41f2296..af7b01586 100644 --- a/src/Options.php +++ b/src/Options.php @@ -68,7 +68,7 @@ public function shouldWriteFile(string $file, bool $overwrite): bool exec('git status --short --ignored --untracked-files=all -- '.ProcessExecutor::escape($file).' 2>&1', $output, $status); if (0 !== $status) { - return $this->io && $this->io->askConfirmation(sprintf('Cannot determine the state of the "%s" file, overwrite anyway? [y/N] ', $file), false); + return $this->io && $this->io->askConfirmation(\sprintf('Cannot determine the state of the "%s" file, overwrite anyway? [y/N] ', $file), false); } if (empty($output[0]) || preg_match('/^[ AMDRCU][ D][ \t]/', $output[0])) { @@ -78,7 +78,7 @@ public function shouldWriteFile(string $file, bool $overwrite): bool $name = basename($file); $name = \strlen($output[0]) - \strlen($name) === strrpos($output[0], $name) ? substr($output[0], 3) : $name; - return $this->io && $this->io->askConfirmation(sprintf('File "%s" has uncommitted changes, overwrite? [y/N] ', $name), false); + return $this->io && $this->io->askConfirmation(\sprintf('File "%s" has uncommitted changes, overwrite? [y/N] ', $name), false); } public function toArray(): array diff --git a/src/PackageFilter.php b/src/PackageFilter.php index 091bcd79b..8de0b5006 100644 --- a/src/PackageFilter.php +++ b/src/PackageFilter.php @@ -101,7 +101,7 @@ public function removeLegacyPackages(array $data, RootPackageInterface $rootPack if ('symfony/symfony' === $name) { $symfonyPackages[] = $package; } elseif (null !== $this->io) { - $this->io->writeError(sprintf('Restricting packages listed in "symfony/symfony" to "%s"', $this->symfonyRequire)); + $this->io->writeError(\sprintf('Restricting packages listed in "symfony/symfony" to "%s"', $this->symfonyRequire)); $this->io = null; } } diff --git a/src/PackageJsonSynchronizer.php b/src/PackageJsonSynchronizer.php index 698894c5b..97af6e146 100644 --- a/src/PackageJsonSynchronizer.php +++ b/src/PackageJsonSynchronizer.php @@ -264,7 +264,7 @@ private function updateImportMap(array $importMapEntries): void continue; } - $this->io->writeError(sprintf('Updating package %s from %s to %s.', $name, $version, $versionConstraint)); + $this->io->writeError(\sprintf('Updating package %s from %s to %s.', $name, $version, $versionConstraint)); } if (isset($importMapEntry['path'])) { @@ -293,7 +293,7 @@ private function updateImportMap(array $importMapEntries): void continue; } - throw new \InvalidArgumentException(sprintf('Invalid importmap entry: "%s".', var_export($importMapEntry, true))); + throw new \InvalidArgumentException(\sprintf('Invalid importmap entry: "%s".', var_export($importMapEntry, true))); } } diff --git a/src/PackageResolver.php b/src/PackageResolver.php index c7a7e5eb6..3e25584a5 100644 --- a/src/PackageResolver.php +++ b/src/PackageResolver.php @@ -131,7 +131,7 @@ private function throwAlternatives(string $argument, int $position) // First position can only be a package name, not a version if ($alternatives || 0 === $position) { - $message = sprintf('"%s" is not a valid alias.', $argument); + $message = \sprintf('"%s" is not a valid alias.', $argument); if ($alternatives) { if (1 === \count($alternatives)) { $message .= " Did you mean this:\n"; @@ -139,11 +139,11 @@ private function throwAlternatives(string $argument, int $position) $message .= " Did you mean one of these:\n"; } foreach ($alternatives as $package => $aliases) { - $message .= sprintf(" \"%s\", supported aliases: \"%s\"\n", $package, implode('", "', $aliases)); + $message .= \sprintf(" \"%s\", supported aliases: \"%s\"\n", $package, implode('", "', $aliases)); } } } else { - $message = sprintf('Could not parse version constraint "%s".', $argument); + $message = \sprintf('Could not parse version constraint "%s".', $argument); } throw new \UnexpectedValueException($message); diff --git a/src/ParallelDownloader.php b/src/ParallelDownloader.php index bfa95d305..52c7bbb09 100644 --- a/src/ParallelDownloader.php +++ b/src/ParallelDownloader.php @@ -80,7 +80,7 @@ public function download(array &$nextArgs, callable $nextCallback, bool $quiet = } $this->io->writeError(''); - $this->io->writeError(sprintf('Prefetching %d packages %s', $this->downloadCount, $note)); + $this->io->writeError(\sprintf('Prefetching %d packages %s', $this->downloadCount, $note)); $this->io->writeError(' - Downloading', false); if ($this->progress) { $this->io->writeError(' (0%)', false); @@ -118,17 +118,11 @@ public function setNextOptions(array $options) return $this; } - /** - * {@inheritdoc} - */ public function getLastHeaders(): array { return $this->lastHeaders ?? parent::getLastHeaders(); } - /** - * {@inheritdoc} - */ public function copy($originUrl, $fileUrl, $fileName, $progress = true, $options = []) { $options = array_replace_recursive($this->nextOptions, $options); @@ -145,9 +139,6 @@ public function copy($originUrl, $fileUrl, $fileName, $progress = true, $options } } - /** - * {@inheritdoc} - */ public function getContents($originUrl, $fileUrl, $progress = true, $options = []) { return $this->copy($originUrl, $fileUrl, null, $progress, $options); @@ -197,7 +188,7 @@ public function callbackGet($notificationCode, $severity, $message, $messageCode if (5 <= $progress - $state->lastProgress || 1 <= $progressTime - $state->lastUpdate) { $state->lastProgress = $progress; - $this->io->overwriteError(sprintf(' (%d%%)', $progress), false); + $this->io->overwriteError(\sprintf(' (%d%%)', $progress), false); $state->lastUpdate = microtime(true); } } @@ -213,9 +204,6 @@ public function callbackGet($notificationCode, $severity, $message, $messageCode } } - /** - * {@inheritdoc} - */ protected function getRemoteContents($originUrl, $fileUrl, $context, ?array &$responseHeaders = null, $maxFileSize = null) { if (isset(self::$cache[$fileUrl])) { diff --git a/src/Recipe.php b/src/Recipe.php index 3c8697245..b02ceab32 100644 --- a/src/Recipe.php +++ b/src/Recipe.php @@ -51,7 +51,7 @@ public function getJob(): string public function getManifest(): array { if (!isset($this->data['manifest'])) { - throw new \LogicException(sprintf('Manifest is not available for recipe "%s".', $this->name)); + throw new \LogicException(\sprintf('Manifest is not available for recipe "%s".', $this->name)); } return $this->data['manifest']; @@ -78,7 +78,7 @@ public function getFormattedOrigin(): string return $this->getOrigin(); } - return sprintf('%s (>=%s): From %s', $matches[1], $matches[2], 'auto-generated recipe' === $matches[3] ? ''.$matches[3].'' : $matches[3]); + return \sprintf('%s (>=%s): From %s', $matches[1], $matches[2], 'auto-generated recipe' === $matches[3] ? ''.$matches[3].'' : $matches[3]); } public function getURL(): string @@ -93,7 +93,7 @@ public function getURL(): string return ''; } - return sprintf('https://%s/tree/%s/%s/%s', $matches[3], $matches[4], $matches[1], $matches[2]); + return \sprintf('https://%s/tree/%s/%s/%s', $matches[3], $matches[4], $matches[1], $matches[2]); } public function isContrib(): bool diff --git a/src/ScriptExecutor.php b/src/ScriptExecutor.php index 9aa3327f5..fb1becd9b 100644 --- a/src/ScriptExecutor.php +++ b/src/ScriptExecutor.php @@ -54,20 +54,20 @@ public function execute(string $type, string $cmd, array $arguments = []) $cmdOutput->write($buffer, false, OutputInterface::OUTPUT_RAW); }; - $this->io->writeError(sprintf('Executing script %s', $parsedCmd), $this->io->isVerbose()); + $this->io->writeError(\sprintf('Executing script %s', $parsedCmd), $this->io->isVerbose()); $exitCode = $this->executor->execute($expandedCmd, $outputHandler); $code = 0 === $exitCode ? ' [OK]' : ' [KO]'; if ($this->io->isVerbose()) { - $this->io->writeError(sprintf('Executed script %s %s', $cmd, $code)); + $this->io->writeError(\sprintf('Executed script %s %s', $cmd, $code)); } else { $this->io->writeError($code); } if (0 !== $exitCode) { $this->io->writeError(' [KO]'); - $this->io->writeError(sprintf('Script %s returned with error code %s', $cmd, $exitCode)); + $this->io->writeError(\sprintf('Script %s returned with error code %s', $cmd, $exitCode)); fseek($cmdOutput->getStream(), 0); foreach (explode("\n", stream_get_contents($cmdOutput->getStream())) as $line) { $this->io->writeError('!! '.$line); @@ -87,7 +87,7 @@ private function expandCmd(string $type, string $cmd, array $arguments) case 'script': return $cmd; default: - throw new \InvalidArgumentException(sprintf('Invalid symfony/flex auto-script in composer.json: "%s" is not a valid type of command.', $type)); + throw new \InvalidArgumentException(\sprintf('Invalid symfony/flex auto-script in composer.json: "%s" is not a valid type of command.', $type)); } } @@ -95,7 +95,7 @@ private function expandSymfonyCmd(string $cmd, array $arguments) { $repo = $this->composer->getRepositoryManager()->getLocalRepository(); if (!$repo->findPackage('symfony/console', class_exists(MatchAllConstraint::class) ? new MatchAllConstraint() : new EmptyConstraint())) { - $this->io->writeError(sprintf('Skipping "%s" (needs symfony/console to run).', $cmd)); + $this->io->writeError(\sprintf('Skipping "%s" (needs symfony/console to run).', $cmd)); return null; } diff --git a/src/Unpacker.php b/src/Unpacker.php index ddc0cb189..fdc6177e6 100644 --- a/src/Unpacker.php +++ b/src/Unpacker.php @@ -55,10 +55,10 @@ public function unpack(Operation $op, ?Result $result = null, &$links = [], bool // not unpackable or no --unpack flag or empty packs (markers) if ( - null === $pkg || - 'symfony-pack' !== $pkg->getType() || - !$op->shouldUnpack() || - 0 === \count($pkg->getRequires()) + \count($pkg->getDevRequires()) + null === $pkg + || 'symfony-pack' !== $pkg->getType() + || !$op->shouldUnpack() + || 0 === \count($pkg->getRequires()) + \count($pkg->getDevRequires()) ) { $result->addRequired($package['name'].($package['version'] ? ':'.$package['version'] : '')); @@ -77,7 +77,7 @@ public function unpack(Operation $op, ?Result $result = null, &$links = [], bool foreach ($devRequires as $i => $link) { if (!isset($requires[$link->getTarget()])) { - throw new \RuntimeException(sprintf('Symfony pack "%s" must duplicate all entries from "require-dev" into "require" but entry "%s" was not found.', $package['name'], $link->getTarget())); + throw new \RuntimeException(\sprintf('Symfony pack "%s" must duplicate all entries from "require-dev" into "require" but entry "%s" was not found.', $package['name'], $link->getTarget())); } $devRequires[$i] = $requires[$link->getTarget()]; unset($requires[$link->getTarget()]); @@ -164,7 +164,7 @@ public function unpack(Operation $op, ?Result $result = null, &$links = [], bool $constraint = end($link['constraints']); if (!$jsonManipulator->addLink($link['type'], $link['name'], $constraint->getPrettyString(), $op->shouldSort())) { - throw new \RuntimeException(sprintf('Unable to unpack package "%s".', $link['name'])); + throw new \RuntimeException(\sprintf('Unable to unpack package "%s".', $link['name'])); } } diff --git a/src/Update/DiffHelper.php b/src/Update/DiffHelper.php index 707288958..f4e23cdf7 100644 --- a/src/Update/DiffHelper.php +++ b/src/Update/DiffHelper.php @@ -16,9 +16,9 @@ class DiffHelper public static function removeFilesFromPatch(string $patch, array $files, array &$removedPatches): string { foreach ($files as $filename) { - $start = strpos($patch, sprintf('diff --git a/%s b/%s', $filename, $filename)); + $start = strpos($patch, \sprintf('diff --git a/%s b/%s', $filename, $filename)); if (false === $start) { - throw new \LogicException(sprintf('Could not find file "%s" in the patch.', $filename)); + throw new \LogicException(\sprintf('Could not find file "%s" in the patch.', $filename)); } $end = strpos($patch, 'diff --git a/', $start + 1); @@ -37,7 +37,7 @@ public static function removeFilesFromPatch(string $patch, array $files, array & // valid patches end with a blank line if ($patch && "\n" !== substr($patch, \strlen($patch) - 1, 1)) { - $patch = $patch."\n"; + $patch .= "\n"; } return $patch; diff --git a/src/Update/RecipePatcher.php b/src/Update/RecipePatcher.php index 1de2b34f6..69eb7c1d6 100644 --- a/src/Update/RecipePatcher.php +++ b/src/Update/RecipePatcher.php @@ -42,7 +42,7 @@ public function applyPatch(RecipePatch $patch): bool foreach ($patch->getDeletedFiles() as $deletedFile) { if (file_exists($this->rootDir.'/'.$deletedFile)) { - $this->execute(sprintf('git rm %s', ProcessExecutor::escape($deletedFile)), $this->rootDir); + $this->execute(\sprintf('git rm %s', ProcessExecutor::escape($deletedFile)), $this->rootDir); } } @@ -106,7 +106,7 @@ public function generatePatch(array $originalFiles, array $newFiles): RecipePatc $this->writeFiles($newFiles, $tmpPath); $this->execute('git add -A', $tmpPath); - $patchString = $this->execute(sprintf('git diff --cached --src-prefix "a/%s" --dst-prefix "b/%s"', $prefix, $prefix), $tmpPath); + $patchString = $this->execute(\sprintf('git diff --cached --src-prefix "a/%s" --dst-prefix "b/%s"', $prefix, $prefix), $tmpPath); $removedPatches = []; $patchString = DiffHelper::removeFilesFromPatch($patchString, $deletedModifiedFiles, $removedPatches); @@ -151,7 +151,7 @@ private function execute(string $command, string $cwd): string $statusCode = $this->processExecutor->execute($command, $output, $cwd); if (0 !== $statusCode) { - throw new \LogicException(sprintf('Command "%s" failed: "%s". Output: "%s".', $command, $this->processExecutor->getErrorOutput(), $output)); + throw new \LogicException(\sprintf('Command "%s" failed: "%s". Output: "%s".', $command, $this->processExecutor->getErrorOutput(), $output)); } return $output; @@ -252,7 +252,7 @@ private function getIgnoredFiles(array $fileNames): array { $args = implode(' ', array_map([ProcessExecutor::class, 'escape'], $fileNames)); $output = ''; - $this->processExecutor->execute(sprintf('git check-ignore %s', $args), $output, $this->rootDir); + $this->processExecutor->execute(\sprintf('git check-ignore %s', $args), $output, $this->rootDir); return $this->processExecutor->splitLines($output); } diff --git a/tests/Configurator/BundlesConfiguratorTest.php b/tests/Configurator/BundlesConfiguratorTest.php index 1a7ff6ad1..924577c27 100644 --- a/tests/Configurator/BundlesConfiguratorTest.php +++ b/tests/Configurator/BundlesConfiguratorTest.php @@ -49,7 +49,7 @@ public function testConfigure() ]; EOF - , file_get_contents($config)); + , file_get_contents($config)); } public function testConfigureWhenBundlesAlreadyExists() @@ -86,7 +86,7 @@ public function testConfigureWhenBundlesAlreadyExists() ]; EOF - , file_get_contents(FLEX_TEST_DIR.'/config/bundles.php')); + , file_get_contents(FLEX_TEST_DIR.'/config/bundles.php')); } public function testUnconfigure() @@ -123,7 +123,7 @@ public function testUnconfigure() ]; EOF - , file_get_contents(FLEX_TEST_DIR.'/config/bundles.php')); + , file_get_contents(FLEX_TEST_DIR.'/config/bundles.php')); } public function testUpdate() diff --git a/tests/Configurator/CopyFromPackageConfiguratorTest.php b/tests/Configurator/CopyFromPackageConfiguratorTest.php index b9b8e2e6b..8a5366b3f 100644 --- a/tests/Configurator/CopyFromPackageConfiguratorTest.php +++ b/tests/Configurator/CopyFromPackageConfiguratorTest.php @@ -15,7 +15,6 @@ use Composer\Installer\InstallationManager; use Composer\IO\IOInterface; use Composer\Package\PackageInterface; -use LogicException; use PHPUnit\Framework\TestCase; use Symfony\Flex\Configurator\CopyFromPackageConfigurator; use Symfony\Flex\Lock; @@ -74,8 +73,8 @@ public function testConfigureAndOverwriteFiles() public function testSourceFileNotExist() { $this->io->expects($this->once())->method('writeError')->with([' Copying files from package']); - $this->expectException(LogicException::class); - $this->expectExceptionMessage(sprintf('File "%s" does not exist!', $this->sourceFile)); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage(\sprintf('File "%s" does not exist!', $this->sourceFile)); $lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock(); $this->createConfigurator()->configure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock); } diff --git a/tests/FlexTest.php b/tests/FlexTest.php index 070454609..cabb08a42 100644 --- a/tests/FlexTest.php +++ b/tests/FlexTest.php @@ -163,7 +163,7 @@ public function getPackagesForAutoDiscovery(): array } $expectedManifest = [ - 'origin' => sprintf('%s:%s@auto-generated recipe', $package->getName(), + 'origin' => \sprintf('%s:%s@auto-generated recipe', $package->getName(), $package->getPrettyVersion()), 'manifest' => ['bundles' => []], ]; diff --git a/tests/PackageFilterTest.php b/tests/PackageFilterTest.php index 80f721784..0b7292e8b 100644 --- a/tests/PackageFilterTest.php +++ b/tests/PackageFilterTest.php @@ -78,8 +78,8 @@ private function configToPackage(array $configs) foreach ($configs as $name => $versions) { foreach ($versions as $version => $extra) { $packages[] = $l->load([ - 'name' => $name, - 'version' => $version, + 'name' => $name, + 'version' => $version, ] + $extra, CompletePackage::class); } } diff --git a/tests/PackageJsonSynchronizerTest.php b/tests/PackageJsonSynchronizerTest.php index 7e6b27c0d..70f7dc64f 100644 --- a/tests/PackageJsonSynchronizerTest.php +++ b/tests/PackageJsonSynchronizerTest.php @@ -396,7 +396,7 @@ public function testSynchronizeAssetMapperUpgradesPackageIfNeeded() 'version' => '1.8.0', ], ]; - file_put_contents($this->tempDir.'/importmap.php', sprintf('tempDir.'/importmap.php', \sprintf('tempDir.'/vendor/symfony/new-package/assets/dist/loader.js'; $this->scriptExecutor->expects($this->exactly(2)) @@ -422,7 +422,7 @@ public function testSynchronizeAssetMapperSkipsUpgradeIfAlreadySatisfied() 'version' => '1.9.1', ], ]; - file_put_contents($this->tempDir.'/importmap.php', sprintf('tempDir.'/importmap.php', \sprintf('tempDir.'/vendor/symfony/new-package/assets/dist/loader.js'; $this->scriptExecutor->expects($this->once())