mirror of
https://github.com/symfony/ux-toolkit.git
synced 2026-03-24 00:02:08 +01:00
Run PHP-CS-Fixer (no_useless_else & static_lambda)
This commit is contained in:
@@ -44,7 +44,7 @@ class CreateKitCommand extends Command
|
||||
|
||||
// Get the kit name
|
||||
$question = new Question("What's the name of your kit?");
|
||||
$question->setValidator(function (?string $value) {
|
||||
$question->setValidator(static function (?string $value) {
|
||||
if (empty($value)) {
|
||||
throw new \RuntimeException('Kit name cannot be empty.');
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class CreateKitCommand extends Command
|
||||
|
||||
// Get the kit homepage
|
||||
$question = new Question("What's the Homepage URL of your kit?");
|
||||
$question->setValidator(function (?string $value) {
|
||||
$question->setValidator(static function (?string $value) {
|
||||
if (empty($value) || !filter_var($value, \FILTER_VALIDATE_URL)) {
|
||||
throw new \Exception('The homepage URL must be valid.');
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class CreateKitCommand extends Command
|
||||
|
||||
// Get the kit license
|
||||
$question = new Question('What is the license of your kit?');
|
||||
$question->setValidator(function (string $value) {
|
||||
$question->setValidator(static function (string $value) {
|
||||
if (empty($value)) {
|
||||
throw new \Exception('The license cannot be empty.');
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class InstallCommand extends Command
|
||||
}
|
||||
// If more than one kit is available, we ask the user which one to use
|
||||
if (($availableKitsCount = \count($availableKits)) > 1) {
|
||||
$kitName = $io->choice(null === $recipeName ? 'Which Kit do you want to use?' : \sprintf('The recipe "%s" exists in multiple Kits. Which one do you want to use?', $recipeName), array_map(fn (Kit $kit) => $kit->manifest->name, $availableKits));
|
||||
$kitName = $io->choice(null === $recipeName ? 'Which Kit do you want to use?' : \sprintf('The recipe "%s" exists in multiple Kits. Which one do you want to use?', $recipeName), array_map(static fn (Kit $kit) => $kit->manifest->name, $availableKits));
|
||||
|
||||
foreach ($availableKits as $availableKit) {
|
||||
if ($availableKit->manifest->name === $kitName) {
|
||||
@@ -133,7 +133,7 @@ class InstallCommand extends Command
|
||||
|
||||
if (null === $recipeName) {
|
||||
// Ask for the recipe name if not provided
|
||||
$recipeName = $io->choice('Which recipe do you want to install?', array_map(fn (Recipe $recipe) => $recipe->manifest->name, $kit->getRecipes()));
|
||||
$recipeName = $io->choice('Which recipe do you want to install?', array_map(static fn (Recipe $recipe) => $recipe->manifest->name, $kit->getRecipes()));
|
||||
$recipe = $kit->getRecipe(name: $recipeName);
|
||||
} elseif (null === $recipe = $kit->getRecipe($recipeName)) {
|
||||
// Suggest alternatives if recipe does not exist
|
||||
@@ -150,7 +150,7 @@ class InstallCommand extends Command
|
||||
return Command::FAILURE;
|
||||
}
|
||||
} elseif ($alternativeRecipesCount > 0) {
|
||||
$io->warning(\sprintf('%s'."\n".'Possible alternatives: "%s"', $message, implode('", "', array_map(fn (Recipe $r) => $r->name, $alternativeRecipes))));
|
||||
$io->warning(\sprintf('%s'."\n".'Possible alternatives: "%s"', $message, implode('", "', array_map(static fn (Recipe $r) => $r->name, $alternativeRecipes))));
|
||||
|
||||
return Command::FAILURE;
|
||||
} else {
|
||||
@@ -174,7 +174,7 @@ class InstallCommand extends Command
|
||||
$this->io->success('The recipe has been installed.');
|
||||
|
||||
$this->io->section('Installed files');
|
||||
$this->io->listing(array_map(fn (File $file) => Path::join($destinationPath, $file->sourceRelativePathName), $installationReport->newFiles));
|
||||
$this->io->listing(array_map(static fn (File $file) => Path::join($destinationPath, $file->sourceRelativePathName), $installationReport->newFiles));
|
||||
|
||||
if ([] !== $installationReport->suggestedPhpPackages || [] !== $installationReport->suggestedNpmPackages || [] !== $installationReport->suggestedImportmapPackages) {
|
||||
$this->io->section('Next steps');
|
||||
@@ -226,7 +226,7 @@ class InstallCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
usort($alternativeRecipes, fn (Recipe $recipeA, Recipe $recipeB) => strcmp($recipeA->name, $recipeB->name));
|
||||
usort($alternativeRecipes, static fn (Recipe $recipeA, Recipe $recipeB) => strcmp($recipeA->name, $recipeB->name));
|
||||
|
||||
return $alternativeRecipes;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ final class Kit
|
||||
public function getRecipes(?RecipeType $type = null): array
|
||||
{
|
||||
if (null !== $type) {
|
||||
return array_filter($this->recipes, fn (Recipe $recipe) => $recipe->manifest->type === $type);
|
||||
return array_filter($this->recipes, static fn (Recipe $recipe) => $recipe->manifest->type === $type);
|
||||
}
|
||||
|
||||
return $this->recipes;
|
||||
|
||||
@@ -59,7 +59,7 @@ final class RecipeManifest
|
||||
|
||||
$type = $data['type'] ?? throw new \InvalidArgumentException('Property "type" is required.');
|
||||
if (null === $type = RecipeType::tryFrom($type)) {
|
||||
throw new \InvalidArgumentException(\sprintf('The recipe type "%s" is not supported, valid types are "%s".', $data['type'], implode('", "', array_map(fn (RecipeType $type) => $type->value, RecipeType::cases()))));
|
||||
throw new \InvalidArgumentException(\sprintf('The recipe type "%s" is not supported, valid types are "%s".', $data['type'], implode('", "', array_map(static fn (RecipeType $type) => $type->value, RecipeType::cases()))));
|
||||
}
|
||||
|
||||
$dependencies = [];
|
||||
|
||||
@@ -70,7 +70,7 @@ class ComponentsRenderingTest extends WebTestCase
|
||||
|
||||
$kit = $this->instantiateKit($kitName);
|
||||
$template = $twig->createTemplate($code);
|
||||
$renderedCode = $kitContextRunner->runForKit($kit, fn () => $template->render());
|
||||
$renderedCode = $kitContextRunner->runForKit($kit, static fn () => $template->render());
|
||||
|
||||
$this->assertCodeRenderedMatchesHtmlSnapshot($kit, $kit->getRecipe($recipeName), $code, $renderedCode);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ final class InstallerTest extends KernelTestCase
|
||||
|
||||
public function testCanInstallComponent()
|
||||
{
|
||||
$installer = new Installer(self::getContainer()->get('filesystem'), fn () => throw new \BadFunctionCallException('The installer should not ask for confirmation since the file does not exist.'));
|
||||
$installer = new Installer(self::getContainer()->get('filesystem'), static fn () => throw new \BadFunctionCallException('The installer should not ask for confirmation since the file does not exist.'));
|
||||
$kit = $this->createKit('shadcn');
|
||||
|
||||
$this->assertFileDoesNotExist($this->tmpDir.'/Button.html.twig');
|
||||
@@ -52,7 +52,7 @@ final class InstallerTest extends KernelTestCase
|
||||
public function testShouldAskIfFileAlreadyExists()
|
||||
{
|
||||
$askedCount = 0;
|
||||
$installer = new Installer(self::getContainer()->get('filesystem'), function () use (&$askedCount) {
|
||||
$installer = new Installer(self::getContainer()->get('filesystem'), static function () use (&$askedCount) {
|
||||
++$askedCount;
|
||||
|
||||
return true;
|
||||
@@ -74,7 +74,7 @@ final class InstallerTest extends KernelTestCase
|
||||
|
||||
public function testCanInstallComponentIfForced()
|
||||
{
|
||||
$installer = new Installer(self::getContainer()->get('filesystem'), fn () => throw new \BadFunctionCallException('The installer should not ask for confirmation since the file does not exist.'));
|
||||
$installer = new Installer(self::getContainer()->get('filesystem'), static fn () => throw new \BadFunctionCallException('The installer should not ask for confirmation since the file does not exist.'));
|
||||
$kit = $this->createKit('shadcn');
|
||||
|
||||
$recipe = $kit->getRecipe('button');
|
||||
@@ -93,7 +93,7 @@ final class InstallerTest extends KernelTestCase
|
||||
|
||||
public function testCanInstallComponentAndItsComponentDependencies()
|
||||
{
|
||||
$installer = new Installer(self::getContainer()->get('filesystem'), fn () => throw new \BadFunctionCallException('The installer should not ask for confirmation since the file does not exist.'));
|
||||
$installer = new Installer(self::getContainer()->get('filesystem'), static fn () => throw new \BadFunctionCallException('The installer should not ask for confirmation since the file does not exist.'));
|
||||
$kit = $this->createKit('shadcn');
|
||||
|
||||
$expectedFiles = [
|
||||
|
||||
@@ -55,8 +55,8 @@ class KitContextRunnerTest extends KernelTestCase
|
||||
*/
|
||||
private function extractComponentFactoryState(ComponentFactory $componentFactory): array
|
||||
{
|
||||
$componentTemplateFinder = \Closure::bind(fn (ComponentFactory $componentFactory) => $componentFactory->componentTemplateFinder, null, $componentFactory)($componentFactory);
|
||||
$config = \Closure::bind(fn (ComponentFactory $componentFactory) => $componentFactory->config, null, $componentFactory)($componentFactory);
|
||||
$componentTemplateFinder = \Closure::bind(static fn (ComponentFactory $componentFactory) => $componentFactory->componentTemplateFinder, null, $componentFactory)($componentFactory);
|
||||
$config = \Closure::bind(static fn (ComponentFactory $componentFactory) => $componentFactory->config, null, $componentFactory)($componentFactory);
|
||||
|
||||
return ['componentTemplateFinder' => $componentTemplateFinder, 'config' => $config];
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ final class GitHubRegistryTest extends KernelTestCase
|
||||
$isHttpClientCalled = false;
|
||||
$zipShadcnMain = $this->createZip('repo', 'shadcn', 'main');
|
||||
|
||||
$httpClient = new MockHttpClient(function (string $method, string $url) use ($zipShadcnMain, &$isHttpClientCalled) {
|
||||
$httpClient = new MockHttpClient(static function (string $method, string $url) use ($zipShadcnMain, &$isHttpClientCalled) {
|
||||
if ('GET' === $method && 'https://github.com/user/repo/archive/main.zip' === $url) {
|
||||
$isHttpClientCalled = true;
|
||||
|
||||
@@ -75,7 +75,7 @@ final class GitHubRegistryTest extends KernelTestCase
|
||||
$githubRegistry = new GitHubRegistry(
|
||||
self::getContainer()->get('ux_toolkit.kit.kit_factory'),
|
||||
$this->filesystem,
|
||||
new MockHttpClient(fn () => new MockResponse(
|
||||
new MockHttpClient(static fn () => new MockResponse(
|
||||
'Not found',
|
||||
[
|
||||
'http_code' => 404,
|
||||
|
||||
Reference in New Issue
Block a user