Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS fixes #1037

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
2 changes: 1 addition & 1 deletion src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function removeLegacyTags(array $data): array

if (!$this->symfonyConstraints->matches($constraint)) {
if (null !== $this->io) {
$this->io->writeError(sprintf('<info>Restricting packages listed in "symfony/symfony" to "%s"</>', $this->symfonyRequire));
$this->io->writeError(\sprintf('<info>Restricting packages listed in "symfony/symfony" to "%s"</>', $this->symfonyRequire));
$this->io = null;
}
unset($versions[$version]);
Expand Down
4 changes: 2 additions & 2 deletions src/Command/DumpEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
Expand Down
10 changes: 5 additions & 5 deletions src/Command/InstallRecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<warning>Cannot update: some packages are not installed:</warning> %s', implode(', ', $invalidPackages)));
$io->writeError(\sprintf('<warning>Cannot update: some packages are not installed:</warning> %s', implode(', ', $invalidPackages)));

return 1;
}

if ($packagesRequiringForce = array_diff($targetPackages, $packages)) {
$io->writeError(sprintf('Recipe(s) already installed for: <info>%s</info>', implode(', ', $packagesRequiringForce)));
$io->writeError(\sprintf('Recipe(s) already installed for: <info>%s</info>', implode(', ', $packagesRequiringForce)));
$io->writeError('Re-run the command with <info>--force</info> to re-install the recipes.');
$io->writeError('');
}
Expand All @@ -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('<error>Package %s is not installed</>', $package));
$io->writeError(\sprintf('<error>Package %s is not installed</>', $package));

return 1;
}
Expand All @@ -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');
}
Expand Down Expand Up @@ -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(' <comment>git mv %s %s</> && <comment>%s %s %1$s</>', ProcessExecutor::escape($root.$dotenvFile), ProcessExecutor::escape($root.$dotenvFile.'.dist'), $win ? 'rename' : 'mv', ProcessExecutor::escape($root.$dotenvFile.'.local'));
$output[] = \sprintf(' <comment>git mv %s %s</> && <comment>%s %s %1$s</>', ProcessExecutor::escape($root.$dotenvFile), ProcessExecutor::escape($root.$dotenvFile.'.dist'), $win ? 'rename' : 'mv', ProcessExecutor::escape($root.$dotenvFile.'.local'));
$output[] = '';
}

Expand Down
16 changes: 8 additions & 8 deletions src/Command/RecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<error>Package %s is not installed</error>', $name));
$this->getIO()->writeError(\sprintf('<error>Package %s is not installed</error>', $name));

continue;
}
Expand Down Expand Up @@ -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
Expand All @@ -136,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->getIO()->write(array_merge([
'',
'<bg=blue;fg=white> </>',
sprintf('<bg=blue;fg=white> %s recipes. </>', $outdated ? ' Outdated' : 'Available'),
\sprintf('<bg=blue;fg=white> %s recipes. </>', $outdated ? ' Outdated' : 'Available'),
'<bg=blue;fg=white> </>',
'',
], $write, [
Expand Down Expand Up @@ -200,7 +200,7 @@ private function displayPackageInformation(Recipe $recipe)
$io->write('<info>version</info> : '.($lockVersion ?? 'n/a'));
$io->write('<info>status</info> : '.$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"
Expand All @@ -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,
Expand Down Expand Up @@ -249,7 +249,7 @@ private function displayPackageInformation(Recipe $recipe)
$io->write([
'',
'Update this recipe by running:',
sprintf('<info>composer recipes:update %s</info>', $recipe->getName()),
\sprintf('<info>composer recipes:update %s</info>', $recipe->getName()),
]);
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ private function displayFilesTree(array $tree)
$treeBar = '└';
}

$info = sprintf(
$info = \sprintf(
'%s──%s',
$treeBar,
$dir
Expand All @@ -319,7 +319,7 @@ private function displayTree(array $tree, $previousTreeBar = '├', $level = 1)
$treeBar = $previousTreeBar.' └';
}

$info = sprintf(
$info = \sprintf(
'%s──%s',
$treeBar,
$dir
Expand Down
4 changes: 2 additions & 2 deletions src/Command/UnpackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<error>Package %s is not installed</>', $package['name']));
$io->writeError(\sprintf('<error>Package %s is not installed</>', $package['name']));

return 1;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->writeError('<info>Unpacking Symfony packs</>');
foreach ($result->getUnpacked() as $pkg) {
$io->writeError(sprintf(' - Unpacked <info>%s</>', $pkg->getName()));
$io->writeError(\sprintf(' - Unpacked <info>%s</>', $pkg->getName()));
}

$unpacker->updateLock($result, $io);
Expand Down
24 changes: 12 additions & 12 deletions src/Command/UpdateRecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <info>composer recipes:install %s --force -v</info> to re-install the recipe.', $packageName),
\sprintf('Try running <info>composer recipes:install %s --force -v</info> to re-install the recipe.', $packageName),
]);

return 1;
Expand All @@ -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(' <info>composer recipes:install %s --force -v</info>', $packageName),
\sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
]);

return 1;
Expand All @@ -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(' <info>composer recipes:install %s --force -v</info>', $packageName),
\sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
]);

return 1;
Expand All @@ -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(' <info>composer recipes:install %s --force -v</info>', $packageName),
\sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
]);

return 1;
Expand All @@ -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 <info>%s</info> is already at the latest version.', $packageName));
$io->write(\sprintf('This recipe for <info>%s</info> is already at the latest version.', $packageName));

return 0;
}

$io->write([
sprintf(' Updating recipe for <info>%s</info>...', $packageName),
\sprintf(' Updating recipe for <info>%s</info>...', $packageName),
'',
]);

Expand All @@ -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(' <info>composer recipes:install %s --force -v</info>', $packageName),
\sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
]);

return 1;
Expand Down Expand Up @@ -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([
'',
Expand All @@ -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 <comment>%s</comment> was not updated because it doesn\'t exist in your app.', array_keys($patch->getRemovedPatches())[0]),
\sprintf(' The file <comment>%s</comment> 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(' * <comment>%s</comment>', $filename);
$notes[] = \sprintf(' * <comment>%s</comment>', $filename);
}
}
$io->write([
Expand All @@ -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 <info>%s</info>', $patchFilename),
\sprintf(' Saved diff to <info>%s</info>', $patchFilename),
]);
}
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
8 changes: 4 additions & 4 deletions src/Configurator/AbstractConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <!-- ###- %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");
}

/**
Expand Down
Loading