E5D6 PHP CS Fixer: enable `@PHP8x1Migration:risky` by keradus · Pull Request #63198 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Open
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
11 changes: 3 additions & 8 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRules([
'@PHP8x1Migration' => true, // take lowest version from `git grep -h '"php"' **/composer.json | uniq | sort`
'@PHP8x1Migration:risky' => true,
'@PHPUnit9x1Migration:risky' => true, // take version from src/Symfony/Bridge/PhpUnit/phpunit.xml.dist#L4
'@Symfony' => true,
'@Symfony:risky' => true,
Expand All @@ -44,15 +45,9 @@
'/s',
]),
],
'declare_strict_types' => false, // part of PHP?x?Migration:risky, awaits https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/9384
'php_unit_attributes' => true,
'random_api_migration' => [ // PHP migration awaits
'replacements' => [
'mt_getrandmax' => 'getrandmax',
'mt_rand' => 'random_int',
'mt_srand' => 'srand',
'rand' => 'random_int',
],
],
'void_return' => false, // part of PHP?x?Migration:risky, usage to be concluded
])
->setRuleCustomisationPolicy(new class implements PhpCsFixer\Config\RuleCustomisationPolicyInterface {
public function getPolicyVersionForCache(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,10 @@ private function createRegistryForManagers(array $managers, bool $withExpectatio

if ($withExpectations) {
$registry->expects($this->any())->method('getManagerNames')->willReturn(array_combine(array_keys($managers), array_keys($managers)));
$registry->expects($this->any())->method('getManager')->willReturnCallback(static function (?string $name) use ($managers, $defaultName): ?EntityManagerInterface {
return $managers[$name ?? $defaultName] ?? null;
});
$registry->expects($this->any())->method('getManager')->willReturnCallback(static fn (?string $name): ?EntityManagerInterface => $managers[$name ?? $defaultName] ?? null);
} else {
$registry->method('getManagerNames')->willReturn(array_combine(array_keys($managers), array_keys($managers)));
$registry->method('getManager')->willReturnCallback(static function (?string $name) use ($managers, $defaultName): ?EntityManagerInterface {
return $managers[$name ?? $defaultName] ?? null;
});
$registry->method('getManager')->willReturnCallback(static fn (?string $name): ?EntityManagerInterface => $managers[$name ?? $defaultName] ?? null);
}

return $registry;
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ private static function colorize(string $str, bool $red): string
*/
private function displayDeprecations(array $groups, Configuration $configuration): void
{
$cmp = static function ($a, $b) {
return $b->count() - $a->count();
};
$cmp = static fn ($a, $b) => $b->count() - $a->count();

if ($configuration->shouldWriteToLogFile()) {
if (false === $handle = @fopen($file = $configuration->getLogFile(), 'a')) {
Expand Down Expand Up @@ -398,7 +396,7 @@ private static function getPhpUnitErrorHandler(): callable
}
}

return static function () { return false; };
return static fn () => false;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@
'requires' => ['php' => '*'],
];

$stableVersions = array_filter($info['versions'], static function ($v) {
return !preg_match('/-dev$|^dev-/', $v);
});
$stableVersions = array_filter($info['versions'], static fn ($v) => !preg_match('/-dev$|^dev-/', $v));

if (!$stableVersions) {
$passthruOrFail("$COMPOSER create-project --ignore-platform-reqs --no-install --prefer-dist --no-scripts --no-plugins --no-progress -s dev phpunit/phpunit $PHPUNIT_VERSION_DIR \"$PHPUNIT_VERSION.*\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function getFiles(array $uploadedFiles): array
*/
private function createUploadedFile(UploadedFileInterface $psrUploadedFile): UploadedFile
{
return new UploadedFile($psrUploadedFile, function () { return $this->getTemporaryPath(); });
return new UploadedFile($psrUploadedFile, fn () => $this->getTemporaryPath());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ public static function requestProvider(): array

return array_merge([
[$sfRequest, $psr17Factory, $symfonyFactory],
], array_map(static function ($psr7Request) use ($symfonyFactory, $psr17Factory) {
return [$psr7Request, $symfonyFactory, $psr17Factory];
}, $psr7Requests));
], array_map(static fn ($psr7Request) => [$psr7Request, $symfonyFactory, $psr17Factory], $psr7Requests));
}

#[DataProvider('responseProvider')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ protected function setUp(): void
'yes',
'no',
],
'choice_label' => static function (string $choice) {
return new TranslatableMessage('parametrized.%value%', ['%value%' => $choice], 'forms');
},
'choice_label' => static fn (string $choice) => new TranslatableMessage('parametrized.%value%', ['%value%' => $choice], 'forms'),
])
->getForm()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,21 +848,15 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode, callable $enabl
->end()
->end()
->validate()
->ifTrue(static function ($v) {
return isset($v['version_strategy']) && isset($v['version']);
})
->ifTrue(static fn ($v) => isset($v['version_strategy']) && isset($v['version']))
->thenInvalid('You cannot use both "version_strategy" and "version" at the same time under "assets".')
->end()
->validate()
->ifTrue(static function ($v) {
return isset($v['version_strategy']) && isset($v['json_manifest_path']);
})
->ifTrue(static fn ($v) => isset($v['version_strategy']) && isset($v['json_manifest_path']))
->thenInvalid('You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets".')
->end()
->validate()
->ifTrue(static function ($v) {
return isset($v['version']) && isset($v['json_manifest_path']);
})
->ifTrue(static fn ($v) => isset($v['version']) && isset($v['json_manifest_path']))
->thenInvalid('You cannot use both "version" and "json_manifest_path" at the same time under "assets".')
->end()
->children()
Expand Down Expand Up @@ -892,21 +886,15 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode, callable $enabl
->end()
->end()
->validate()
->ifTrue(static function ($v) {
return isset($v['version_strategy']) && isset($v['version']);
})
->ifTrue(static fn ($v) => isset($v['version_strategy']) && isset($v['version']))
->thenInvalid('You cannot use both "version_strategy" and "version" at the same time under "assets" packages.')
->end()
->validate()
->ifTrue(static function ($v) {
return isset($v['version_strategy']) && isset($v['json_manifest_path']);
})
->ifTrue(static fn ($v) => isset($v['version_strategy']) && isset($v['json_manifest_path']))
->thenInvalid('You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets" packages.')
->end()
->validate()
->ifTrue(static function ($v) {
return isset($v['version']) && isset($v['json_manifest_path']);
})
->ifTrue(static fn ($v) => isset($v['version']) && isset($v['json_manifest_path']))
->thenInvalid('You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.')
->end()
->end()
Expand Down Expand Up @@ -1685,9 +1673,7 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode, callable $en
];
} else {
$newConfig[$v['message-class']]['senders'] = array_map(
static function ($a) {
return \is_string($a) ? $a : $a['service'];
},
static fn ($a) => \is_string($a) ? $a : $a['service'],
array_values($v['sender'])
);
}
Expand Down Expand Up @@ -2423,9 +2409,7 @@ private function addMailerSection(ArrayNodeDefinition $rootNode, callable $enabl
})
->end()
->validate()
->ifTrue(static function ($v) {
return \extension_loaded('openssl') && null !== $v && !\defined('OPENSSL_CIPHER_'.$v);
})
->ifTrue(static fn ($v) => \extension_loaded('openssl') && null !== $v && !\defined('OPENSSL_CIPHER_'.$v))
->thenInvalid('You must provide a valid cipher.')
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ public function dispatch(object $event, ?string $eventName = null): object

$this->assertEquals($actualDecisionLog, $expectedDecisionLog, 'Wrong value returned by getAccessDecisionLog');

$actualVoterClasses = array_map(static function (ClassStub $classStub): string {
return (string) $classStub;
}, $dataCollector->getVoters());
$actualVoterClasses = array_map(static fn (ClassStub $classStub): string => (string) $classStub, $dataCollector->getVoters());

$expectedVoterClasses = [
$voter1::class,
Expand Down Expand Up @@ -385,9 +383,7 @@ public function dispatch(object $event, ?string $eventName = null): object

$this->assertEquals($actualDecisionLog, $expectedDecisionLog, 'Wrong value returned by getAccessDecisionLog');

$actualVoterClasses = array_map(static function (ClassStub $classStub): string {
return (string) $classStub;
}, $dataCollector->getVoters());
$actualVoterClasses = array_map(static fn (ClassStub $classStub): string => (string) $classStub, $dataCollector->getVoters());

$expectedVoterClasses = [
$voter1::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public function testFalseNegativeTrace()

$matchedRouteCell = $crawler
->filter('#router-logs .status-success td')
->reduce(static function (Crawler $td) use ($path): bool {
return $td->text() === $path;
});
->reduce(static fn (Crawler $td): bool => $td->text() === $path);

$this->assertSame(1, $matchedRouteCell->count());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$pathRows[] = [$path, $namespace];
}
uasort($pathRows, static function (array $a, array $b): int {
return [(bool) $a[1], ...$a] <=> [(bool) $b[1], ...$b];
});
uasort($pathRows, static fn (array $a, array $b): int => [(bool) $a[1], ...$a] <=> [(bool) $b[1], ...$b]);
if ($pathRows) {
$io->table(['Path', 'Namespace prefix'], $pathRows);
} else {
Expand All @@ -121,9 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->shortenPath($row[1]),
], $rows);
}
uasort($rows, static function (array $a, array $b): int {
return [$a] <=> [$b];
});
uasort($rows, static fn (array $a, array $b): int => [$a] <=> [$b]);
$io->table(['Logical Path', 'Filesystem Path'], $rows);
if ($this->didShortenPaths) {
$io->note('To see the full paths, re-run with the --full option.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ private function createFactory(?AssetCompilerInterface $extraCompiler = null, ?s
$pathResolver = $this->createStub(PublicAssetsPathResolverInterface::class);
$pathResolver
->method('resolvePublicPath')
->willReturnCallback(static function (string $logicalPath) {
return '/final-assets/'.$logicalPath;
});
->willReturnCallback(static fn (string $logicalPath) => '/final-assets/'.$logicalPath);

$factory = new MappedAssetFactory(
$pathResolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public function testGetEntriesAndWriteEntries()
$remotePackageStorage = $this->createStub(RemotePackageStorage::class);
$remotePackageStorage
->method('getDownloadPath')
->willReturnCallback(static function (string $packageModuleSpecifier, ImportMapType $type) {
return '/path/to/vendor/'.$packageModuleSpecifier.'.'.$type->value;
});
->willReturnCallback(static fn (string $packageModuleSpecifier, ImportMapType $type) => '/path/to/vendor/'.$packageModuleSpecifier.'.'.$type->value);
$reader = new ImportMapConfigReader(
__DIR__.'/../Fixtures/importmap_config_reader/importmap.php',
$remotePackageStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public function testRequire(array $packages, int $expectedProviderPackageArgumen

$this->packageResolver->expects($this->exactly(0 === $expectedProviderPackageArgumentCount ? 0 : 1))
->method('resolvePackages')
->with($this->callback(static function (array $packages) use ($expectedProviderPackageArgumentCount) {
return \count($packages) === $expectedProviderPackageArgumentCount;
}))
->with($this->callback(static fn (array $packages) => \count($packages) === $expectedProviderPackageArgumentCount))
->willReturn($resolvedPackages)
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public function testGetUrl(string $path, string $expectedPathSentToInner)
$inner->expects($this->once())
->method('getUrl')
->with($expectedPathSentToInner)
->willReturnCallback(static function ($path) {
return '/'.$path;
});
->willReturnCallback(static fn ($path) => '/'.$path);
$assetMapper = $this->createStub(AssetMapperInterface::class);
$assetMapper
->method('getPublicPath')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ private function callConfigurator(callable $callback, DefinitionConfigurator $co
final class ProtectedDefinitionFileLoader extends DefinitionFileLoader
{
}

// @php-cs-fixer-ignore use_arrow_functions to prevent arrow function overriding callback that includes file in limited context, ref https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/9388
4 changes: 1 addition & 3 deletions src/Symfony/Component/Console/Attribute/Ask.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public static function tryFrom(\ReflectionParameter|\ReflectionProperty $member,
$question->setTimeout($self->timeout);

if (!$self->validator && $reflection->isProperty() && 'array' !== $type->getName()) {
$self->validator = function (mixed $value) use ($reflection): mixed {
return $this->{$reflection->getName()} = $value;
};
$self->validator = fn (mixed $value): mixed => $this->{$reflection->getName()} = $value;
}

$question->setValidator($self->validator);
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Console/Attribute/AskChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ public static function tryFrom(\ReflectionParameter|\ReflectionProperty $member,
$question->setMaxAttempts($self->maxAttempts);

if (!$self->validator && $reflection->isProperty() && !$isBackedEnum && 'array' !== $type->getName()) {
$self->validator = function (mixed $value) use ($reflection): mixed {
return $this->{$reflection->getName()} = $value;
};
$self->validator = fn (mixed $value): mixed => $this->{$reflection->getName()} = $value;
}

if ($self->validator) {
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Console/Command/TraceableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public function __construct(
parent::__construct($command->getName());

// init below enables calling {@see parent::run()}
[$code, $processTitle, $ignoreValidationErrors] = \Closure::bind(function () {
return [$this->code, $this->processTitle, $this->ignoreValidationErrors];
}, $command, Command::class)();
[$code, $processTitle, $ignoreValidationErrors] = \Closure::bind(fn () => [$this->code, $this->processTitle, $this->ignoreValidationErrors], $command, Command::class)();

if (\is_callable($code)) {
$this->setCode($code);
Expand Down Expand Up @@ -169,9 +167,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
public function setCode(callable $code): static
{
if ($code instanceof InvokableCommand) {
$r = \Closure::bind(function () {
return $this->invokable;
}, $code, InvokableCommand::class)();
$r = \Closure::bind(fn () => $this->invokable, $code, InvokableCommand::class)();

$this->invokableCommandInfo = [
'class' => $r->getClosureScopeClass()->name,
Expand Down
12 changes: 4 additions & 8 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1324,9 +1324,7 @@ public function testAddingOptionWithDuplicateShortcut()
->register('foo')
->setAliases(['f'])
->setDefinition([new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')])
->setCode(static function (InputInterface $input, OutputInterface $output): int {
return 0;
})
->setCode(static fn (InputInterface $input, OutputInterface $output): int => 0)
;

$input = new ArrayInput(['command' => 'foo']);
Expand All @@ -1347,9 +1345,7 @@ public function testAddingAlreadySetDefinitionElementData($def)
$application
->register('foo')
->setDefinition([$def])
->setCode(static function (InputInterface $input, OutputInterface $output): int {
return 0;
})
->setCode(static fn (InputInterface $input, OutputInterface $output): int => 0)
;

$input = new ArrayInput(['command' => 'foo']);
Expand Down Expand Up @@ -1946,12 +1942,12 @@ public function testFindAlternativesDoesNotLoadSameNamespaceCommandsOnExactMatch
'foo:bar' => static function () use (&$loaded) {
$loaded['foo:bar'] = true;

return (new Command('foo:bar'))->setCode(static function (): int { return 0; });
return (new Command('foo:bar'))->setCode(static fn (): int => 0);
},
'foo' => static function () use (&$loaded) {
$loaded['foo'] = true;

return (new Command('foo'))->setCode(static function (): int { return 0; });
return (new Command('foo'))->setCode(static fn (): int => 0);
},
]));

Expand Down
Loading
Loading
0