From cefa0740806dc2099b3e1808abab29e8503ec502 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Sat, 24 May 2025 19:17:39 +0200 Subject: [PATCH] Homogenize PHP-CS-Fixer configuration with symfony/symfony, and run it --- .php-cs-fixer.dist.php | 32 ++++++++++++++----- src/Icons/config/twig_component.php | 1 - .../src/Util/LiveAttributesCollection.php | 4 --- .../src/Util/TwigAttributeHelperFactory.php | 2 -- .../LiveComponentSubscriberTest.php | 2 -- .../DataModelPropsSubscriberTest.php | 1 - .../src/Command/InstallComponentCommand.php | 2 +- .../tests/Unit/TwigPreLexerTest.php | 6 ++-- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index a8c7da94b14..35eb7c6c53d 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -13,14 +13,19 @@ exit(0); } -$fileHeaderComment = <<<'EOF' -This file is part of the Symfony package. +$fileHeaderParts = [ + <<<'EOF' + This file is part of the Symfony package. -(c) Fabien Potencier + (c) Fabien Potencier -For the full copyright and license information, please view the LICENSE -file that was distributed with this source code. -EOF; + EOF, + <<<'EOF' + + For the full copyright and license information, please view the LICENSE + file that was distributed with this source code. + EOF, +]; return (new PhpCsFixer\Config()) ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()) @@ -28,8 +33,17 @@ '@PHPUnit75Migration:risky' => true, '@Symfony' => true, '@Symfony:risky' => true, - 'header_comment' => ['header' => $fileHeaderComment], - 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']], + 'protected_to_private' => false, + 'header_comment' => [ + 'header' => implode('', $fileHeaderParts), + 'validator' => implode('', [ + '/', + preg_quote($fileHeaderParts[0], '/'), + '(?P.*)??', + preg_quote($fileHeaderParts[1], '/'), + '/s', + ]), + ], ]) ->setRiskyAllowed(true) ->setFinder( @@ -38,5 +52,7 @@ ->append([__FILE__]) ->notPath('#/Fixtures/#') ->notPath('#/var/#') + // does not work well with `fully_qualified_strict_types` rule + ->notPath('LiveComponent/tests/Integration/LiveComponentHydratorTest.php') ) ; diff --git a/src/Icons/config/twig_component.php b/src/Icons/config/twig_component.php index 5e27cc81ff7..0b65f64fa7a 100644 --- a/src/Icons/config/twig_component.php +++ b/src/Icons/config/twig_component.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; use Symfony\UX\Icons\Twig\UXIconComponent; -use Symfony\UX\Icons\Twig\UXIconComponentListener; return static function (ContainerConfigurator $container): void { $container->services() diff --git a/src/LiveComponent/src/Util/LiveAttributesCollection.php b/src/LiveComponent/src/Util/LiveAttributesCollection.php index c09287c9d65..a39cbac0deb 100644 --- a/src/LiveComponent/src/Util/LiveAttributesCollection.php +++ b/src/LiveComponent/src/Util/LiveAttributesCollection.php @@ -11,10 +11,6 @@ namespace Symfony\UX\LiveComponent\Util; -use Twig\Environment; -use Twig\Extension\EscaperExtension; -use Twig\Runtime\EscaperRuntime; - /** * A collection of HTML attributes useful for LiveComponent. * diff --git a/src/LiveComponent/src/Util/TwigAttributeHelperFactory.php b/src/LiveComponent/src/Util/TwigAttributeHelperFactory.php index 9f729ce8d28..68b7ccf264f 100644 --- a/src/LiveComponent/src/Util/TwigAttributeHelperFactory.php +++ b/src/LiveComponent/src/Util/TwigAttributeHelperFactory.php @@ -11,8 +11,6 @@ namespace Symfony\UX\LiveComponent\Util; -use Twig\Environment; - /** * Helper for building an array of attributes for the live controller element. * diff --git a/src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php b/src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php index 9ac59da9123..c5141554923 100644 --- a/src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php +++ b/src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php @@ -12,8 +12,6 @@ namespace Symfony\UX\LiveComponent\Tests\Functional\EventListener; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -use Symfony\Component\DomCrawler\Crawler; -use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Security\Core\User\InMemoryUser; use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\Entity1; diff --git a/src/LiveComponent/tests/Integration/EventListener/DataModelPropsSubscriberTest.php b/src/LiveComponent/tests/Integration/EventListener/DataModelPropsSubscriberTest.php index 1d04d03d6f9..60d1f6e6b3f 100644 --- a/src/LiveComponent/tests/Integration/EventListener/DataModelPropsSubscriberTest.php +++ b/src/LiveComponent/tests/Integration/EventListener/DataModelPropsSubscriberTest.php @@ -12,7 +12,6 @@ namespace Symfony\UX\LiveComponent\Tests\Integration\EventListener; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -use Symfony\Component\HttpFoundation\Request; use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper; use Symfony\UX\TwigComponent\ComponentRenderer; diff --git a/src/Toolkit/src/Command/InstallComponentCommand.php b/src/Toolkit/src/Command/InstallComponentCommand.php index 83dd56eebf9..6746a6d5272 100644 --- a/src/Toolkit/src/Command/InstallComponentCommand.php +++ b/src/Toolkit/src/Command/InstallComponentCommand.php @@ -123,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } else { $io->error(null === $componentName ? 'It seems that no local kits are available and it should not happens. Please open an issue on https://github.com/symfony/ux to report this.' - : sprintf("The component \"%s\" does not exist in any local kits.\n\nYou can try to run one of the following commands to interactively install components:\n%s\n\nOr you can try one of the community kits https://github.com/search?q=topic:ux-toolkit&type=repositories", $componentName, implode("\n", array_map(fn (string $availableKitName) => sprintf('$ bin/console %s --kit %s', $this->getName(), $availableKitName), $availableKitNames))) + : \sprintf("The component \"%s\" does not exist in any local kits.\n\nYou can try to run one of the following commands to interactively install components:\n%s\n\nOr you can try one of the community kits https://github.com/search?q=topic:ux-toolkit&type=repositories", $componentName, implode("\n", array_map(fn (string $availableKitName) => \sprintf('$ bin/console %s --kit %s', $this->getName(), $availableKitName), $availableKitNames))) ); return Command::FAILURE; diff --git a/src/TwigComponent/tests/Unit/TwigPreLexerTest.php b/src/TwigComponent/tests/Unit/TwigPreLexerTest.php index 2878fb3bc74..6165cab3c75 100644 --- a/src/TwigComponent/tests/Unit/TwigPreLexerTest.php +++ b/src/TwigComponent/tests/Unit/TwigPreLexerTest.php @@ -168,7 +168,7 @@ public static function getLexTests(): iterable {% component 'foo' %} {% block content %}{% component 'bar' %}{% block content %}bar content{% endblock %}{% endcomponent %} {% endblock %}{% endcomponent %} - EOF + EOF, ]; yield 'component_where_entire_default_block_is_embedded_component_self_closing' => [ << [ @@ -293,7 +293,7 @@ public static function getLexTests(): iterable 'src/Twig/MealPlanner.php', 'templates/components/MealPlanner.html.twig', ] }) }} - EOF + EOF, ]; yield 'component_with_dashed_attribute' => [