Skip to content

Commit a7a37d9

Browse files
committed
minor symfony#1037 CS fixes (rosier)
This PR was squashed before being merged into the 1.x branch. Discussion ---------- CS fixes I did split this in separate commits to make it easier to review. I can squash this if you prefer that. Commits ------- f34d820 CS fixes
2 parents fd20265 + f34d820 commit a7a37d9

38 files changed

+167
-191
lines changed

.php-cs-fixer.dist.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44

55
return (new PhpCsFixer\Config())
66
->setFinder($finder)
7-
->setRules(array(
7+
->setRules([
88
'@Symfony' => true,
99
'@Symfony:risky' => true,
1010
'fopen_flags' => false,
11-
'@PHPUnit48Migration:risky' => true,
12-
'array_syntax' => ['syntax' => 'short'],
13-
'ordered_imports' => true,
14-
'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
15-
'nullable_type_declaration_for_default_null_value' => true,
11+
'modernize_strpos' => false, // requires PHP 8
1612
'protected_to_private' => false,
17-
))
13+
])
1814
->setRiskyAllowed(true)
1915
;

src/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function removeLegacyTags(array $data): array
8787

8888
if (!$this->symfonyConstraints->matches($constraint)) {
8989
if (null !== $this->io) {
90-
$this->io->writeError(sprintf('<info>Restricting packages listed in "symfony/symfony" to "%s"</>', $this->symfonyRequire));
90+
$this->io->writeError(\sprintf('<info>Restricting packages listed in "symfony/symfony" to "%s"</>', $this->symfonyRequire));
9191
$this->io = null;
9292
}
9393
unset($versions[$version]);

src/Command/DumpEnvCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8484
private function loadEnv(string $path, ?string $env, array $runtime): array
8585
{
8686
if (!file_exists($autoloadFile = $this->config->get('vendor-dir').'/autoload.php')) {
87-
throw new \RuntimeException(sprintf('Please run "composer install" before running this command: "%s" not found.', $autoloadFile));
87+
throw new \RuntimeException(\sprintf('Please run "composer install" before running this command: "%s" not found.', $autoloadFile));
8888
}
8989

9090
require $autoloadFile;
@@ -112,7 +112,7 @@ private function loadEnv(string $path, ?string $env, array $runtime): array
112112
}
113113

114114
if (!$env) {
115-
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));
115+
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));
116116
}
117117

118118
$testEnvs = $runtime['test_envs'] ?? ['test'];

src/Command/InstallRecipesCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8989

9090
if ($targetPackages = $input->getArgument('packages')) {
9191
if ($invalidPackages = array_diff($targetPackages, $totalPackages)) {
92-
$io->writeError(sprintf('<warning>Cannot update: some packages are not installed:</warning> %s', implode(', ', $invalidPackages)));
92+
$io->writeError(\sprintf('<warning>Cannot update: some packages are not installed:</warning> %s', implode(', ', $invalidPackages)));
9393

9494
return 1;
9595
}
9696

9797
if ($packagesRequiringForce = array_diff($targetPackages, $packages)) {
98-
$io->writeError(sprintf('Recipe(s) already installed for: <info>%s</info>', implode(', ', $packagesRequiringForce)));
98+
$io->writeError(\sprintf('Recipe(s) already installed for: <info>%s</info>', implode(', ', $packagesRequiringForce)));
9999
$io->writeError('Re-run the command with <info>--force</info> to re-install the recipes.');
100100
$io->writeError('');
101101
}
@@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
115115
$operations = [];
116116
foreach ($packages as $package) {
117117
if (null === $pkg = $installedRepo->findPackage($package, '*')) {
118-
$io->writeError(sprintf('<error>Package %s is not installed</>', $package));
118+
$io->writeError(\sprintf('<error>Package %s is not installed</>', $package));
119119

120120
return 1;
121121
}
@@ -129,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
129129
if ($createEnvLocal = $force && file_exists($dotenvPath) && file_exists($dotenvPath.'.dist') && !file_exists($dotenvPath.'.local')) {
130130
rename($dotenvPath, $dotenvPath.'.local');
131131
$pipes = [];
132-
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));
132+
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));
133133
if (file_exists($this->rootDir.'/phpunit.xml.dist')) {
134134
touch($dotenvPath.'.test');
135135
}
@@ -164,7 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
164164
if ($createEnvLocal) {
165165
$root = '.' !== $this->rootDir ? $this->rootDir.'/' : '';
166166
$output[] = ' To revert the changes made to .env files, run';
167-
$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'));
167+
$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'));
168168
$output[] = '';
169169
}
170170

src/Command/RecipesCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8080
$pkgVersion = $this->symfonyLock->get($name)['version'];
8181
$pkg = new Package($name, $pkgVersion, $pkgVersion);
8282
} elseif (!$pkg) {
83-
$this->getIO()->writeError(sprintf('<error>Package %s is not installed</error>', $name));
83+
$this->getIO()->writeError(\sprintf('<error>Package %s is not installed</error>', $name));
8484

8585
continue;
8686
}
@@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
125125
}
126126

127127
$hasOutdatedRecipes = true;
128-
$write[] = sprintf(' * %s %s', $name, $additional);
128+
$write[] = \sprintf(' * %s %s', $name, $additional);
129129
}
130130

131131
// Nothing to display
@@ -136,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
136136
$this->getIO()->write(array_merge([
137137
'',
138138
'<bg=blue;fg=white> </>',
139-
sprintf('<bg=blue;fg=white> %s recipes. </>', $outdated ? ' Outdated' : 'Available'),
139+
\sprintf('<bg=blue;fg=white> %s recipes. </>', $outdated ? ' Outdated' : 'Available'),
140140
'<bg=blue;fg=white> </>',
141141
'',
142142
], $write, [
@@ -200,7 +200,7 @@ private function displayPackageInformation(Recipe $recipe)
200200
$io->write('<info>version</info> : '.($lockVersion ?? 'n/a'));
201201
$io->write('<info>status</info> : '.$status);
202202
if (!$recipe->isAuto() && null !== $lockVersion) {
203-
$recipeUrl = sprintf(
203+
$recipeUrl = \sprintf(
204204
'https://%s/tree/%s/%s/%s',
205205
$lockRepo,
206206
// if something fails, default to the branch as the closest "sha"
@@ -217,7 +217,7 @@ private function displayPackageInformation(Recipe $recipe)
217217
}
218218

219219
if ($lockRef !== $recipe->getRef() && null !== $lockVersion) {
220-
$historyUrl = sprintf(
220+
$historyUrl = \sprintf(
221221
'https://%s/commits/%s/%s',
222222
$lockRepo,
223223
$lockBranch,
@@ -249,7 +249,7 @@ private function displayPackageInformation(Recipe $recipe)
249249
$io->write([
250250
'',
251251
'Update this recipe by running:',
252-
sprintf('<info>composer recipes:update %s</info>', $recipe->getName()),
252+
\sprintf('<info>composer recipes:update %s</info>', $recipe->getName()),
253253
]);
254254
}
255255
}
@@ -292,7 +292,7 @@ private function displayFilesTree(array $tree)
292292
$treeBar = '';
293293
}
294294

295-
$info = sprintf(
295+
$info = \sprintf(
296296
'%s──%s',
297297
$treeBar,
298298
$dir
@@ -319,7 +319,7 @@ private function displayTree(array $tree, $previousTreeBar = '├', $level = 1)
319319
$treeBar = $previousTreeBar.'';
320320
}
321321

322-
$info = sprintf(
322+
$info = \sprintf(
323323
'%s──%s',
324324
$treeBar,
325325
$dir

src/Command/UnpackCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6464
$op = new Operation(true, $input->getOption('sort-packages') || $composer->getConfig()->get('sort-packages'));
6565
foreach ($versionParser->parseNameVersionPairs($packages) as $package) {
6666
if (null === $pkg = $installedRepo->findPackage($package['name'], '*')) {
67-
$io->writeError(sprintf('<error>Package %s is not installed</>', $package['name']));
67+
$io->writeError(\sprintf('<error>Package %s is not installed</>', $package['name']));
6868

6969
return 1;
7070
}
@@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9393

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

9999
$unpacker->updateLock($result, $io);

src/Command/UpdateRecipesCommand.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9393
if (!$symfonyLock->has($packageName)) {
9494
$io->writeError([
9595
'Package not found inside symfony.lock. It looks like it\'s not installed?',
96-
sprintf('Try running <info>composer recipes:install %s --force -v</info> to re-install the recipe.', $packageName),
96+
\sprintf('Try running <info>composer recipes:install %s --force -v</info> to re-install the recipe.', $packageName),
9797
]);
9898

9999
return 1;
@@ -104,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
104104
$io->writeError([
105105
'It doesn\'t look like this package had a recipe when it was originally installed.',
106106
'To install the latest version of the recipe, if there is one, run:',
107-
sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
107+
\sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
108108
]);
109109

110110
return 1;
@@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
117117
'The version of the installed recipe was not saved into symfony.lock.',
118118
'This is possible if it was installed by an old version of Symfony Flex.',
119119
'Update the recipe by re-installing the latest version with:',
120-
sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
120+
\sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
121121
]);
122122

123123
return 1;
@@ -131,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
131131
$io->writeError([
132132
'The original recipe version you have installed could not be found, it may be too old.',
133133
'Update the recipe by re-installing the latest version with:',
134-
sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
134+
\sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
135135
]);
136136

137137
return 1;
@@ -140,13 +140,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
140140
$newRecipe = $this->getRecipe($package);
141141

142142
if ($newRecipe->getRef() === $originalRecipe->getRef()) {
143-
$io->write(sprintf('This recipe for <info>%s</info> is already at the latest version.', $packageName));
143+
$io->write(\sprintf('This recipe for <info>%s</info> is already at the latest version.', $packageName));
144144

145145
return 0;
146146
}
147147

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

@@ -164,7 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
164164
$throwable->getMessage(),
165165
'',
166166
'Update the recipe by re-installing the latest version with:',
167-
sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
167+
\sprintf(' <info>composer recipes:install %s --force -v</info>', $packageName),
168168
]);
169169

170170
return 1;
@@ -211,7 +211,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
211211
' This recipe copies the following paths from the bundle into your app:',
212212
]);
213213
foreach ($recipeUpdate->getCopyFromPackagePaths() as $source => $target) {
214-
$io->write(sprintf(' * %s => %s', $source, $target));
214+
$io->write(\sprintf(' * %s => %s', $source, $target));
215215
}
216216
$io->write([
217217
'',
@@ -223,12 +223,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
223223
if (0 !== \count($patch->getRemovedPatches())) {
224224
if (1 === \count($patch->getRemovedPatches())) {
225225
$notes = [
226-
sprintf(' The file <comment>%s</comment> was not updated because it doesn\'t exist in your app.', array_keys($patch->getRemovedPatches())[0]),
226+
\sprintf(' The file <comment>%s</comment> was not updated because it doesn\'t exist in your app.', array_keys($patch->getRemovedPatches())[0]),
227227
];
228228
} else {
229229
$notes = [' The following files were not updated because they don\'t exist in your app:'];
230230
foreach ($patch->getRemovedPatches() as $filename => $contents) {
231-
$notes[] = sprintf(' * <comment>%s</comment>', $filename);
231+
$notes[] = \sprintf(' * <comment>%s</comment>', $filename);
232232
}
233233
}
234234
$io->write([
@@ -242,7 +242,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
242242
file_put_contents($this->rootDir.'/'.$patchFilename, implode("\n", $patch->getRemovedPatches()));
243243
$io->write([
244244
'',
245-
sprintf(' Saved diff to <info>%s</info>', $patchFilename),
245+
\sprintf(' Saved diff to <info>%s</info>', $patchFilename),
246246
]);
247247
}
248248
}
@@ -347,7 +347,7 @@ private function generateChangelog(Recipe $originalRecipe): ?array
347347
if ($handlesHrefGracefully) {
348348
$url = "\033]8;;$url\033\\$number\033]8;;\033\\";
349349
}
350-
$lines[] = sprintf(' * %s (PR %s)', $data['title'], $url);
350+
$lines[] = \sprintf(' * %s (PR %s)', $data['title'], $url);
351351
}
352352

353353
return $lines;

src/Configurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function unconfigure(Recipe $recipe, Lock $lock)
104104
private function get($key): AbstractConfigurator
105105
{
106106
if (!isset($this->configurators[$key]) && !isset($this->postInstallConfigurators[$key])) {
107-
throw new \InvalidArgumentException(sprintf('Unknown configurator "%s".', $key));
107+
throw new \InvalidArgumentException(\sprintf('Unknown configurator "%s".', $key));
108108
}
109109

110110
if (isset($this->cache[$key])) {

src/Configurator/AbstractConfigurator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ protected function write($messages, $verbosity = IOInterface::VERBOSE)
5656

5757
protected function isFileMarked(Recipe $recipe, string $file): bool
5858
{
59-
return is_file($file) && false !== strpos(file_get_contents($file), sprintf('###> %s ###', $recipe->getName()));
59+
return is_file($file) && false !== strpos(file_get_contents($file), \sprintf('###> %s ###', $recipe->getName()));
6060
}
6161

6262
protected function markData(Recipe $recipe, string $data): string
6363
{
64-
return "\n".sprintf('###> %s ###%s%s%s###< %s ###%s', $recipe->getName(), "\n", rtrim($data, "\r\n"), "\n", $recipe->getName(), "\n");
64+
return "\n".\sprintf('###> %s ###%s%s%s###< %s ###%s', $recipe->getName(), "\n", rtrim($data, "\r\n"), "\n", $recipe->getName(), "\n");
6565
}
6666

6767
protected function isFileXmlMarked(Recipe $recipe, string $file): bool
6868
{
69-
return is_file($file) && false !== strpos(file_get_contents($file), sprintf('###+ %s ###', $recipe->getName()));
69+
return is_file($file) && false !== strpos(file_get_contents($file), \sprintf('###+ %s ###', $recipe->getName()));
7070
}
7171

7272
protected function markXmlData(Recipe $recipe, string $data): string
7373
{
74-
return "\n".sprintf(' <!-- ###+ %s ### -->%s%s%s <!-- ###- %s ### -->%s', $recipe->getName(), "\n", rtrim($data, "\r\n"), "\n", $recipe->getName(), "\n");
74+
return "\n".\sprintf(' <!-- ###+ %s ### -->%s%s%s <!-- ###- %s ### -->%s', $recipe->getName(), "\n", rtrim($data, "\r\n"), "\n", $recipe->getName(), "\n");
7575
}
7676

7777
/**

0 commit comments

Comments
 (0)