From 6d714cb6af12c07d1c2c60382092c2ae9580aa83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 12 Sep 2024 00:08:39 +0200 Subject: [PATCH] Add coding standard --- .github/workflows/ci.yaml | 3 ++ composer.json | 4 ++- ecs.php | 32 +++++++++++++++++++ src/TwigExtra/config/services.php | 9 ++++++ .../DependencyInjection/Configuration.php | 9 ++++++ .../TwigExtraExtension.php | 9 ++++++ src/TwigExtra/src/Symfony/TwigExtraBundle.php | 9 ++++++ .../src/Twig/Extension/SortByExtension.php | 9 ++++++ .../Extension/TestFormAttributeExtension.php | 9 ++++++ .../Extension/TestHtmlAttributeExtension.php | 9 ++++++ .../src/Twig/Ux/ComponentTemplateFinder.php | 11 ++++++- .../Twig/Extension/SortByExtensionTest.php | 9 ++++++ .../TestFormAttributeExtensionTest.php | 9 ++++++ .../TestHtmlAttributeExtensionTest.php | 9 ++++++ .../TwigExtraExtensionTest.php | 11 ++++++- .../Twig/Extension/SortByExtensionTest.php | 17 +++++++--- .../TestFormAttributeExtensionTest.php | 9 ++++++ .../TestHtmlAttributeExtensionTest.php | 9 ++++++ .../Twig/Ux/ComponentTemplateFinderTest.php | 9 ++++++ src/TwigHooks/config/services.php | 11 +++++++ .../config/services/debug/twig_events.php | 11 +++++++ .../config/services/hook_renderer.php | 11 +++++++ .../config/services/hookable_merger.php | 11 +++++++ .../config/services/hookable_renderer.php | 11 +++++++ .../config/services/live_component.php | 11 +++++++ src/TwigHooks/src/Bag/DataBag.php | 9 ++++++ src/TwigHooks/src/Bag/DataBagInterface.php | 9 ++++++ src/TwigHooks/src/Bag/ScalarDataBag.php | 10 ++++++ .../src/Bag/ScalarDataBagInterface.php | 9 ++++++ .../src/DependencyInjection/Configuration.php | 9 ++++++ .../TwigHooksExtension.php | 9 ++++++ .../src/Hook/Metadata/HookMetadata.php | 9 ++++++ .../Name/CompositeNameNormalizer.php | 9 ++++++ .../Name/NameNormalizerInterface.php | 9 ++++++ .../Prefix/CompositePrefixNormalizer.php | 11 +++++-- .../Prefix/PrefixNormalizerInterface.php | 9 ++++++ .../Prefix/RemoveSectionPartNormalizer.php | 9 ++++++ .../Debug/HookDebugCommentRenderer.php | 11 ++++++- .../Renderer/Debug/HookProfilerRenderer.php | 11 ++++++- .../src/Hook/Renderer/HookRenderer.php | 11 ++++++- .../Hook/Renderer/HookRendererInterface.php | 9 ++++++ .../src/Hookable/AbstractHookable.php | 11 ++++++- .../src/Hookable/DisabledHookable.php | 9 ++++++ .../src/Hookable/HookableComponent.php | 11 ++++++- .../src/Hookable/HookableTemplate.php | 9 ++++++ .../src/Hookable/Merger/HookableMerger.php | 11 ++++++- .../Merger/HookableMergerInterface.php | 9 ++++++ .../Hookable/Metadata/HookableMetadata.php | 9 ++++++ .../Metadata/HookableMetadataFactory.php | 11 ++++++- .../HookableMetadataFactoryInterface.php | 11 ++++++- .../Renderer/CompositeHookableRenderer.php | 13 ++++++-- .../Debug/HookableDebugCommentRenderer.php | 15 +++++++-- .../Debug/HookableProfilerRenderer.php | 11 ++++++- .../Exception/HookRenderException.php | 9 ++++++ .../NoSupportedRendererException.php | 15 +++++++-- .../Renderer/HookableComponentRenderer.php | 12 ++++++- .../Renderer/HookableRendererInterface.php | 9 ++++++ .../Renderer/HookableTemplateRenderer.php | 9 ++++++ .../SupportableHookableRendererInterface.php | 9 ++++++ .../HookableLiveComponentTrait.php | 9 ++++++ .../Hydration/DataBagHydrationExtension.php | 9 ++++++ .../src/Profiler/Dumper/HtmlDumper.php | 15 +++++++-- src/TwigHooks/src/Profiler/HookProfile.php | 15 +++++++-- .../src/Profiler/HookableProfile.php | 11 ++++++- .../src/Profiler/HooksDataCollector.php | 11 ++++++- src/TwigHooks/src/Profiler/Profile.php | 13 ++++++-- .../src/Provider/ComponentPropsProvider.php | 12 ++++++- .../ConfigurationProviderInterface.php | 9 ++++++ .../src/Provider/ContextProviderInterface.php | 10 ++++++ .../Provider/DefaultConfigurationProvider.php | 9 ++++++ .../src/Provider/DefaultContextProvider.php | 9 ++++++ .../Exception/InvalidExpressionException.php | 9 ++++++ .../src/Provider/PropsProviderInterface.php | 10 ++++++ .../src/Registry/HookablesRegistry.php | 11 ++++++- .../Twig/Component/HookableComponentTrait.php | 9 ++++++ .../Exception/NoHookNameProvidedException.php | 9 ++++++ src/TwigHooks/src/Twig/HooksExtension.php | 9 ++++++ src/TwigHooks/src/Twig/Node/HookNode.php | 13 ++++++-- .../src/Twig/Runtime/HooksRuntime.php | 18 +++++++++-- .../src/Twig/TokenParser/HookTokenParser.php | 9 ++++++ src/TwigHooks/src/TwigHooksBundle.php | 9 ++++++ src/TwigHooks/tests/ContainerTestCase.php | 11 ++++++- .../.application/config/bootstrap.php | 17 +++++++--- .../.application/config/bundles.php | 11 +++++++ .../config/packages/framework.php | 11 +++++++ .../.application/config/preload.php | 15 +++++++-- .../Functional/.application/public/index.php | 19 ++++++++--- .../src/Component/DummyComponent.php | 9 ++++++ .../src/Component/DummyLiveComponent.php | 9 ++++++ .../Functional/.application/src/Kernel.php | 11 +++++++ .../Functional/Twig/HookWithSectionsTest.php | 9 ++++++ .../Twig/HookableLiveComponentTest.php | 9 ++++++ .../Twig/HookableTwigComponentTest.php | 9 ++++++ .../Functional/Twig/ParsingHookTagTest.php | 9 ++++++ .../Twig/RestrictingContextScopeTest.php | 9 ++++++ .../DependencyInjection/ConfigurationTest.php | 21 ++++++++---- .../TwigHooksExtensionTest.php | 11 ++++++- .../Twig/Runtime/HooksRuntimeTest.php | 9 ++++++ src/TwigHooks/tests/RenderedTwigTemplate.php | 9 ++++++ src/TwigHooks/tests/TwigTemplateTrait.php | 10 ++++++ src/TwigHooks/tests/Unit/Bag/DataBagTest.php | 9 ++++++ .../CompositeNameNormalizerTest.php | 9 ++++++ .../RemoveSectionPartNormalizerTest.php | 9 ++++++ .../Debug/HookDebugCommentRendererTest.php | 9 ++++++ .../Unit/Hook/Renderer/HookRendererTest.php | 11 ++++++- .../Unit/Hookable/HookableComponentTest.php | 9 ++++++ .../Unit/Hookable/HookableTemplateTest.php | 9 ++++++ .../Hookable/Merger/HookableMergerTest.php | 9 ++++++ .../CompositeHookableRendererTest.php | 9 ++++++ .../HookableDebugCommentRendererTest.php | 9 ++++++ .../HookableComponentRendererTest.php | 11 ++++++- .../Renderer/HookableTemplateRendererTest.php | 9 ++++++ .../tests/Unit/Profiler/HookProfileTest.php | 9 ++++++ .../Unit/Profiler/HookableProfilerTest.php | 9 ++++++ .../Provider/ComponentPropsProviderTest.php | 11 ++++++- .../DefaultConfigurationProviderTest.php | 9 ++++++ .../Provider/DefaultContextProviderTest.php | 9 ++++++ .../Unit/Registry/HookablesRegistryTest.php | 9 ++++++ .../DisabledHookableMotherObject.php | 9 ++++++ .../MotherObject/HookMetadataMotherObject.php | 9 ++++++ .../MotherObject/HookProfileMotherObject.php | 9 ++++++ .../HookableComponentMotherObject.php | 11 ++++++- .../HookableMetadataMotherObject.php | 17 +++++++--- .../HookableProfileMotherObject.php | 9 ++++++ .../HookableTemplateMotherObject.php | 9 ++++++ symfony.lock | 26 +++++++++++++++ 126 files changed, 1260 insertions(+), 70 deletions(-) create mode 100644 ecs.php diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 65b8543e..f2745838 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -58,6 +58,9 @@ jobs: - name: "Check for security vulnerabilities" run: symfony security:check + - name: "Validate coding standard" + run: vendor/bin/ecs check + - name: "Validate Container" run: bin/console lint:container diff --git a/composer.json b/composer.json index 5ecc4e13..af3c0c75 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "phpstan/phpstan": "^1.10", "phpstan/phpstan-symfony": "^1.3", "phpunit/phpunit": "^9.6", + "sylius-labs/coding-standard": "^4.0", "symfony/console": "^6.4 || ^7.0", "symfony/debug-bundle": "^6.4 || ^7.0", "symfony/dom-crawler": "^6.4 || ^7.0", @@ -72,7 +73,8 @@ "config": { "allow-plugins": { "symfony/flex": true, - "symfony/runtime": true + "symfony/runtime": true, + "dealerdirect/phpcodesniffer-composer-installer": true }, "sort-packages": true }, diff --git a/ecs.php b/ecs.php new file mode 100644 index 00000000..ff001c32 --- /dev/null +++ b/ecs.php @@ -0,0 +1,32 @@ +paths([ + __DIR__ . '/src', + ]); + + $ecsConfig->import('vendor/sylius-labs/coding-standard/ecs.php'); + + $ecsConfig->ruleWithConfiguration(HeaderCommentFixer::class, [ + 'location' => 'after_open', + 'header' => +'This file is part of the Sylius package. + +(c) Sylius Sp. z o.o. + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code.', + ]) + ; + $ecsConfig->ruleWithConfiguration(NoSuperfluousPhpdocTagsFixer::class, ['allow_mixed' => true]); + + $ecsConfig->skip([ + InlineDocCommentDeclarationSniff::class . '.MissingVariable', + '**/var/*', + ]); +}; diff --git a/src/TwigExtra/config/services.php b/src/TwigExtra/config/services.php index e8c2caa4..85bea2e6 100644 --- a/src/TwigExtra/config/services.php +++ b/src/TwigExtra/config/services.php @@ -1,5 +1,14 @@ (object) ['number' => 3]]; - $secondData = (object) ['data' => (object) ['number' => 5]]; - $thirdData = (object) ['data' => (object) ['number' => 1]]; + $secondData = (object) ['data' => (object) ['number' => 5]]; + $thirdData = (object) ['data' => (object) ['number' => 1]]; $arrayBeforeSorting = [ $firstData, @@ -141,8 +150,8 @@ public function testItSortsAnArrayOfObjectsByANestedProperty(): void public function testItSortsAnArrayOfArraysByANestedProperty(): void { $firstData = ['data' => ['number' => 3]]; - $secondData = ['data' => ['number' => 5]]; - $thirdData = ['data' => ['number' => 1]]; + $secondData = ['data' => ['number' => 5]]; + $thirdData = ['data' => ['number' => 1]]; $arrayBeforeSorting = [ $firstData, diff --git a/src/TwigExtra/tests/Unit/Twig/Extension/TestFormAttributeExtensionTest.php b/src/TwigExtra/tests/Unit/Twig/Extension/TestFormAttributeExtensionTest.php index edf2ad13..58296124 100644 --- a/src/TwigExtra/tests/Unit/Twig/Extension/TestFormAttributeExtensionTest.php +++ b/src/TwigExtra/tests/Unit/Twig/Extension/TestFormAttributeExtensionTest.php @@ -1,5 +1,14 @@ validateValues($value); + continue; } diff --git a/src/TwigHooks/src/Bag/ScalarDataBagInterface.php b/src/TwigHooks/src/Bag/ScalarDataBagInterface.php index 18622371..dc8c8246 100644 --- a/src/TwigHooks/src/Bag/ScalarDataBagInterface.php +++ b/src/TwigHooks/src/Bag/ScalarDataBagInterface.php @@ -1,5 +1,14 @@ */ diff --git a/src/TwigHooks/src/Hook/Normalizer/Prefix/PrefixNormalizerInterface.php b/src/TwigHooks/src/Hook/Normalizer/Prefix/PrefixNormalizerInterface.php index af789217..36c27381 100644 --- a/src/TwigHooks/src/Hook/Normalizer/Prefix/PrefixNormalizerInterface.php +++ b/src/TwigHooks/src/Hook/Normalizer/Prefix/PrefixNormalizerInterface.php @@ -1,5 +1,14 @@ innerRenderer->render($hookNames, $hookContext)); $renderedParts[] = $this->getClosingDebugComment($hookNames); - return implode(PHP_EOL, $renderedParts); + return implode(\PHP_EOL, $renderedParts); } /** diff --git a/src/TwigHooks/src/Hook/Renderer/Debug/HookProfilerRenderer.php b/src/TwigHooks/src/Hook/Renderer/Debug/HookProfilerRenderer.php index e7ca20f5..f43f020b 100644 --- a/src/TwigHooks/src/Hook/Renderer/Debug/HookProfilerRenderer.php +++ b/src/TwigHooks/src/Hook/Renderer/Debug/HookProfilerRenderer.php @@ -1,5 +1,14 @@ compositeHookableRenderer->render($hookable, $hookableMetadata); } - return implode(PHP_EOL, $renderedHookables); + return implode(\PHP_EOL, $renderedHookables); } } diff --git a/src/TwigHooks/src/Hook/Renderer/HookRendererInterface.php b/src/TwigHooks/src/Hook/Renderer/HookRendererInterface.php index ba3303da..7fc4daa3 100644 --- a/src/TwigHooks/src/Hook/Renderer/HookRendererInterface.php +++ b/src/TwigHooks/src/Hook/Renderer/HookRendererInterface.php @@ -1,5 +1,14 @@ $context * @param array $configuration */ - public function __construct ( + public function __construct( string $hookName, string $name, array $context = [], diff --git a/src/TwigHooks/src/Hookable/DisabledHookable.php b/src/TwigHooks/src/Hookable/DisabledHookable.php index 8cb325bf..2c5afc4a 100644 --- a/src/TwigHooks/src/Hookable/DisabledHookable.php +++ b/src/TwigHooks/src/Hookable/DisabledHookable.php @@ -1,5 +1,14 @@ $context * @param array $configuration */ - public function __construct ( + public function __construct( string $hookName, string $name, public readonly string $component, diff --git a/src/TwigHooks/src/Hookable/HookableTemplate.php b/src/TwigHooks/src/Hookable/HookableTemplate.php index 7a13a02a..a87ad91b 100644 --- a/src/TwigHooks/src/Hookable/HookableTemplate.php +++ b/src/TwigHooks/src/Hookable/HookableTemplate.php @@ -1,5 +1,14 @@ $inputs * * @return array + * * @throws \ReflectionException */ private function createConstructorArguments(string $class, array $inputs): array diff --git a/src/TwigHooks/src/Hookable/Merger/HookableMergerInterface.php b/src/TwigHooks/src/Hookable/Merger/HookableMergerInterface.php index c7a19b52..cc82a947 100644 --- a/src/TwigHooks/src/Hookable/Merger/HookableMergerInterface.php +++ b/src/TwigHooks/src/Hookable/Merger/HookableMergerInterface.php @@ -1,5 +1,14 @@ $prefixes */ - public function create(HookMetadata $hookMetadata, DataBagInterface $context, ScalarDataBagInterface $configuration, array $prefixes = [],): HookableMetadata; + public function create(HookMetadata $hookMetadata, DataBagInterface $context, ScalarDataBagInterface $configuration, array $prefixes = []): HookableMetadata; } diff --git a/src/TwigHooks/src/Hookable/Renderer/CompositeHookableRenderer.php b/src/TwigHooks/src/Hookable/Renderer/CompositeHookableRenderer.php index 108e1f7e..f85c57f5 100644 --- a/src/TwigHooks/src/Hookable/Renderer/CompositeHookableRenderer.php +++ b/src/TwigHooks/src/Hookable/Renderer/CompositeHookableRenderer.php @@ -1,5 +1,14 @@ $renderers */ - public function __construct (iterable $renderers) + public function __construct(iterable $renderers) { foreach ($renderers as $renderer) { if (!$renderer instanceof SupportableHookableRendererInterface) { throw new \InvalidArgumentException( - sprintf('Hookable renderer must be an instance of "%s".', SupportableHookableRendererInterface::class) + sprintf('Hookable renderer must be an instance of "%s".', SupportableHookableRendererInterface::class), ); } diff --git a/src/TwigHooks/src/Hookable/Renderer/Debug/HookableDebugCommentRenderer.php b/src/TwigHooks/src/Hookable/Renderer/Debug/HookableDebugCommentRenderer.php index 38c69955..240a63cb 100644 --- a/src/TwigHooks/src/Hookable/Renderer/Debug/HookableDebugCommentRenderer.php +++ b/src/TwigHooks/src/Hookable/Renderer/Debug/HookableDebugCommentRenderer.php @@ -1,5 +1,14 @@ innerRenderer->render($hookable, $metadata)); $renderedParts[] = $this->getClosingDebugComment($hookable); - return implode(PHP_EOL, $renderedParts); + return implode(\PHP_EOL, $renderedParts); } private function getOpeningDebugComment(AbstractHookable $hookable): string { - list($targetName, $targetValue) = match (get_class($hookable)) { + [$targetName, $targetValue] = match (get_class($hookable)) { HookableTemplate::class => ['template', $hookable->template], HookableComponent::class => ['component', $hookable->component], default => throw new \InvalidArgumentException('Unsupported hookable type.'), @@ -46,7 +55,7 @@ private function getOpeningDebugComment(AbstractHookable $hookable): string private function getClosingDebugComment(AbstractHookable $hookable): string { - list($targetName, $targetValue) = match (get_class($hookable)) { + [$targetName, $targetValue] = match (get_class($hookable)) { HookableTemplate::class => ['template', $hookable->template], HookableComponent::class => ['component', $hookable->component], default => throw new \InvalidArgumentException('Unsupported hookable type.'), diff --git a/src/TwigHooks/src/Hookable/Renderer/Debug/HookableProfilerRenderer.php b/src/TwigHooks/src/Hookable/Renderer/Debug/HookableProfilerRenderer.php index d6d4b8b2..03c46718 100644 --- a/src/TwigHooks/src/Hookable/Renderer/Debug/HookableProfilerRenderer.php +++ b/src/TwigHooks/src/Hookable/Renderer/Debug/HookableProfilerRenderer.php @@ -1,5 +1,14 @@ supports($hookable)) { throw new \InvalidArgumentException( - sprintf('Hookable must be the "%s", but "%s" given.', HookableComponent::class, get_class($hookable)) + sprintf('Hookable must be the "%s", but "%s" given.', HookableComponent::class, get_class($hookable)), ); } diff --git a/src/TwigHooks/src/Hookable/Renderer/HookableRendererInterface.php b/src/TwigHooks/src/Hookable/Renderer/HookableRendererInterface.php index e852743e..6214086b 100644 --- a/src/TwigHooks/src/Hookable/Renderer/HookableRendererInterface.php +++ b/src/TwigHooks/src/Hookable/Renderer/HookableRendererInterface.php @@ -1,5 +1,14 @@ %s%s', PHP_EOL, $this->dumpProfile($profile)); + return sprintf('
%s%s
', \PHP_EOL, $this->dumpProfile($profile)); } private function dumpProfile(Profile $profile): string @@ -38,7 +47,7 @@ private function dumpHookProfile(HookProfile $hookProfile, string $prefix = '', $prefix, $hookProfile->getName(), ); - $str .= PHP_EOL; + $str .= \PHP_EOL; $prefix .= $sibling ? '│ ' : ' '; $numberOfHookables = \count($hookProfile->getHookablesProfiles()); @@ -66,7 +75,7 @@ private function dumpHookableProfile(HookableProfile $hookableProfile, string $p $hookableProfile->getName(), $this->getTargetValue($hookableProfile->getHookable()), ); - $str .= PHP_EOL; + $str .= \PHP_EOL; $prefix .= $sibling ? '│ ' : ' '; $numberOfChildren = \count($hookableProfile->getChildren()); diff --git a/src/TwigHooks/src/Profiler/HookProfile.php b/src/TwigHooks/src/Profiler/HookProfile.php index 997af27a..a5f8371b 100644 --- a/src/TwigHooks/src/Profiler/HookProfile.php +++ b/src/TwigHooks/src/Profiler/HookProfile.php @@ -1,5 +1,14 @@ $hooksNames * @param array $hookablesProfiles */ - public function __construct ( + public function __construct( private array $hooksNames, private array $hookablesProfiles, - private ?HookProfile $parent = null, + private ?self $parent = null, ) { } - public function getParent(): ?HookProfile + public function getParent(): ?self { return $this->parent; } diff --git a/src/TwigHooks/src/Profiler/HookableProfile.php b/src/TwigHooks/src/Profiler/HookableProfile.php index ce25391b..05bd5dd5 100644 --- a/src/TwigHooks/src/Profiler/HookableProfile.php +++ b/src/TwigHooks/src/Profiler/HookableProfile.php @@ -1,5 +1,14 @@ $children */ - public function __construct ( + public function __construct( private HookProfile $parent, private string $name, private AbstractHookable $hookable, diff --git a/src/TwigHooks/src/Profiler/HooksDataCollector.php b/src/TwigHooks/src/Profiler/HooksDataCollector.php index 1ee288a5..ca650b21 100644 --- a/src/TwigHooks/src/Profiler/HooksDataCollector.php +++ b/src/TwigHooks/src/Profiler/HooksDataCollector.php @@ -1,5 +1,14 @@ previousHookProfile = $this->previousHookProfile?->getParent(); $this->currentHookProfile = $this->currentHookProfile?->getParent(); - $this->numberOfHooks++; + ++$this->numberOfHooks; } public function registerHookableRenderStart(AbstractHookable $hookable): void @@ -59,7 +68,7 @@ public function registerHookableRenderStart(AbstractHookable $hookable): void $this->currentHookableProfile = $hookableProfile; $this->currentHookProfile->addHookableProfile($this->currentHookableProfile); - $this->numberOfHookables++; + ++$this->numberOfHookables; } public function registerHookableRenderEnd(int|float|null $duration): void diff --git a/src/TwigHooks/src/Provider/ComponentPropsProvider.php b/src/TwigHooks/src/Provider/ComponentPropsProvider.php index 06a30c1a..5ebc3010 100644 --- a/src/TwigHooks/src/Provider/ComponentPropsProvider.php +++ b/src/TwigHooks/src/Provider/ComponentPropsProvider.php @@ -1,5 +1,14 @@ $array + * * @return array */ private function mapArrayRecursively(callable $callback, array $array): array diff --git a/src/TwigHooks/src/Provider/ConfigurationProviderInterface.php b/src/TwigHooks/src/Provider/ConfigurationProviderInterface.php index a2f050f4..fc42dab4 100644 --- a/src/TwigHooks/src/Provider/ConfigurationProviderInterface.php +++ b/src/TwigHooks/src/Provider/ConfigurationProviderInterface.php @@ -1,5 +1,14 @@ $hookContext + * * @return array */ public function provide(AbstractHookable $hookable, array $hookContext): array; diff --git a/src/TwigHooks/src/Provider/DefaultConfigurationProvider.php b/src/TwigHooks/src/Provider/DefaultConfigurationProvider.php index 3816987c..88f8b40b 100644 --- a/src/TwigHooks/src/Provider/DefaultConfigurationProvider.php +++ b/src/TwigHooks/src/Provider/DefaultConfigurationProvider.php @@ -1,5 +1,14 @@ */ public function provide(HookableComponent $hookable, HookableMetadata $metadata): array; diff --git a/src/TwigHooks/src/Registry/HookablesRegistry.php b/src/TwigHooks/src/Registry/HookablesRegistry.php index c03dc08e..09a57a24 100644 --- a/src/TwigHooks/src/Registry/HookablesRegistry.php +++ b/src/TwigHooks/src/Registry/HookablesRegistry.php @@ -1,5 +1,14 @@ $context + * * @throws RuntimeError */ public function getHookableMetadata(array $context): HookableMetadata @@ -43,6 +53,7 @@ public function getHookableMetadata(array $context): HookableMetadata /** * @param array $context + * * @throws RuntimeError */ public function getHookableContext(array $context): DataBagInterface @@ -52,6 +63,7 @@ public function getHookableContext(array $context): DataBagInterface /** * @param array $context + * * @throws RuntimeError */ public function getHookableConfiguration(array $context): ScalarDataBagInterface @@ -77,8 +89,7 @@ public function renderHook( array $hookContext = [], array $twigVars = [], bool $only = false, - ): string - { + ): string { $hookNames = is_string($hookNames) ? [$hookNames] : $hookNames; $hookNames = array_map([$this->nameNormalizer, 'normalize'], $hookNames); @@ -130,6 +141,7 @@ private function getPrefixes(array $hookContext, ?HookableMetadata $hookableMeta /** * @param array $hookContext * @param array $twigVars + * * @return array */ private function getContext(array $hookContext, array $twigVars, ?HookableMetadata $hookableMetadata, bool $only = false): array diff --git a/src/TwigHooks/src/Twig/TokenParser/HookTokenParser.php b/src/TwigHooks/src/Twig/TokenParser/HookTokenParser.php index 6b699b91..330811c1 100644 --- a/src/TwigHooks/src/Twig/TokenParser/HookTokenParser.php +++ b/src/TwigHooks/src/Twig/TokenParser/HookTokenParser.php @@ -1,5 +1,14 @@ addCompilerPass(new class implements CompilerPassInterface { + $container->addCompilerPass(new class() implements CompilerPassInterface { public function process(ContainerBuilder $container): void { foreach ($container->getDefinitions() as $definition) { diff --git a/src/TwigHooks/tests/Functional/.application/config/bootstrap.php b/src/TwigHooks/tests/Functional/.application/config/bootstrap.php index 5e229741..b71cf176 100644 --- a/src/TwigHooks/tests/Functional/.application/config/bootstrap.php +++ b/src/TwigHooks/tests/Functional/.application/config/bootstrap.php @@ -1,15 +1,24 @@ ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], diff --git a/src/TwigHooks/tests/Functional/.application/config/packages/framework.php b/src/TwigHooks/tests/Functional/.application/config/packages/framework.php index cb7eff64..662a40f6 100644 --- a/src/TwigHooks/tests/Functional/.application/config/packages/framework.php +++ b/src/TwigHooks/tests/Functional/.application/config/packages/framework.php @@ -1,5 +1,16 @@ HookableComponent::class, ], ], - 'supported_hookable_types' + 'supported_hookable_types', ); } @@ -117,7 +126,7 @@ public function testItAllowsToUseComponentShortcut(): void ], ], ], - 'hooks.*' + 'hooks.*', ); } @@ -151,7 +160,7 @@ public function testItAllowsToUseTemplateShortcut(): void ], ], ], - 'hooks.*' + 'hooks.*', ); } @@ -170,7 +179,7 @@ public function testItThrowsExceptionWhenBothTemplateAndComponentShortcutsAreDef ], ], ], - 'You cannot define both "component" and "template" at the same time.' + 'You cannot define both "component" and "template" at the same time.', ); } @@ -189,7 +198,7 @@ public function testItThrowsExceptionWhenPropsAreDefinedForNonComponentHookable( ], ], ], - '"Props" cannot be defined for non-component hookables.' + '"Props" cannot be defined for non-component hookables.', ); } diff --git a/src/TwigHooks/tests/Integration/DependencyInjection/TwigHooksExtensionTest.php b/src/TwigHooks/tests/Integration/DependencyInjection/TwigHooksExtensionTest.php index ddf3644c..8137fe70 100644 --- a/src/TwigHooks/tests/Integration/DependencyInjection/TwigHooksExtensionTest.php +++ b/src/TwigHooks/tests/Integration/DependencyInjection/TwigHooksExtensionTest.php @@ -1,5 +1,14 @@ ['some' => 'context'], 'enabled' => false, ], - ] + ], ], ]); diff --git a/src/TwigHooks/tests/Integration/Twig/Runtime/HooksRuntimeTest.php b/src/TwigHooks/tests/Integration/Twig/Runtime/HooksRuntimeTest.php index 3c93debf..6eea40f2 100644 --- a/src/TwigHooks/tests/Integration/Twig/Runtime/HooksRuntimeTest.php +++ b/src/TwigHooks/tests/Integration/Twig/Runtime/HooksRuntimeTest.php @@ -1,5 +1,14 @@ $context + * * @throws LoaderError * @throws RuntimeError * @throws SyntaxError diff --git a/src/TwigHooks/tests/Unit/Bag/DataBagTest.php b/src/TwigHooks/tests/Unit/Bag/DataBagTest.php index a286a36b..7006aed8 100644 --- a/src/TwigHooks/tests/Unit/Bag/DataBagTest.php +++ b/src/TwigHooks/tests/Unit/Bag/DataBagTest.php @@ -1,5 +1,14 @@ match ($hookable) { $hookableOne => 'hookable_one_rendered', $hookableTwo => 'hookable_two_rendered', - } + }, ); $result = $this->getTestSubject()->render(['hook_name']); diff --git a/src/TwigHooks/tests/Unit/Hookable/HookableComponentTest.php b/src/TwigHooks/tests/Unit/Hookable/HookableComponentTest.php index c9a5fcf0..e9de0705 100644 --- a/src/TwigHooks/tests/Unit/Hookable/HookableComponentTest.php +++ b/src/TwigHooks/tests/Unit/Hookable/HookableComponentTest.php @@ -1,5 +1,14 @@ $metadata, 'some' => 'props', - ] + ], )->willReturn('some-rendered-component'); $renderedComponent = $this->getTestSubject()->render($hookable, $metadata); diff --git a/src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php b/src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php index 74eb4f7f..225c763d 100644 --- a/src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php +++ b/src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php @@ -1,5 +1,14 @@ '@=_configuration.anonymize ? "Anon" : _context.username' + 'name' => '@=_configuration.anonymize ? "Anon" : _context.username', ]); $anonymizeMetadata = HookableMetadataMotherObject::withContextAndConfiguration( context: [ diff --git a/src/TwigHooks/tests/Unit/Provider/DefaultConfigurationProviderTest.php b/src/TwigHooks/tests/Unit/Provider/DefaultConfigurationProviderTest.php index 6d93804d..b5726434 100644 --- a/src/TwigHooks/tests/Unit/Provider/DefaultConfigurationProviderTest.php +++ b/src/TwigHooks/tests/Unit/Provider/DefaultConfigurationProviderTest.php @@ -1,5 +1,14 @@