diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 526f48a..f6a8302 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,8 +1,12 @@ setRiskyAllowed(true) ->setRules([ + '@PER' => true, + '@PER:risky' => true, '@PhpCsFixer' => true, '@PhpCsFixer:risky' => true, @@ -12,14 +16,18 @@ 'multiline_whitespace_before_semicolons' => false, 'native_function_invocation' => ['include' => ['@all']], 'no_superfluous_phpdoc_tags' => false, - 'ordered_imports' => ['imports_order' => ['class', 'function', 'const']], + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'], + 'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'alpha'], + 'php_unit_data_provider_name' => false, 'php_unit_internal_class' => false, 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], 'php_unit_test_class_requires_covers' => false, 'phpdoc_align' => false, + 'phpdoc_order' => ['order' => ['param', 'throws', 'return']], + 'phpdoc_no_alias_tag' => false, 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], 'single_line_comment_style' => false, - 'visibility_required' => ['elements' => ['property', 'method', 'const']], + 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'match', 'parameters']], 'yoda_style' => false, // Additional rules @@ -30,16 +38,16 @@ 'import_constants' => true, 'import_functions' => true, ], - 'list_syntax' => ['syntax' => 'short'], + 'heredoc_indentation' => ['indentation' => 'same_as_start'], 'mb_str_functions' => true, 'native_constant_invocation' => true, 'nullable_type_declaration_for_default_null_value' => true, 'static_lambda' => true, 'ternary_to_null_coalescing' => true, + 'use_arrow_functions' => true, ]) ->setFinder( PhpCsFixer\Finder::create() - ->exclude(['vendor']) - ->in(__DIR__) + ->in(['bundle', 'tests']) ) ; diff --git a/bundle/DependencyInjection/Compiler/MetaTagHandlersCompilerPass.php b/bundle/DependencyInjection/Compiler/MetaTagHandlersCompilerPass.php index 1466263..4b2339f 100644 --- a/bundle/DependencyInjection/Compiler/MetaTagHandlersCompilerPass.php +++ b/bundle/DependencyInjection/Compiler/MetaTagHandlersCompilerPass.php @@ -23,7 +23,7 @@ public function process(ContainerBuilder $container): void foreach ($metaTagHandler as $tag) { if (!isset($tag['alias'])) { throw new LogicException( - 'netgen_open_graph.meta_tag_handler service tag needs an "alias" attribute to identify the handler. None given.' + 'netgen_open_graph.meta_tag_handler service tag needs an "alias" attribute to identify the handler. None given.', ); } @@ -32,7 +32,7 @@ public function process(ContainerBuilder $container): void [ $tag['alias'], new Reference($serviceId), - ] + ], ); } } diff --git a/bundle/DependencyInjection/NetgenOpenGraphExtension.php b/bundle/DependencyInjection/NetgenOpenGraphExtension.php index 3f9c95e..ca1e812 100644 --- a/bundle/DependencyInjection/NetgenOpenGraphExtension.php +++ b/bundle/DependencyInjection/NetgenOpenGraphExtension.php @@ -45,7 +45,7 @@ static function ($scopeSettings, $currentScope, ContextualizerInterface $context foreach ($scopeSettings as $key => $value) { $contextualizer->setContextualParameter($key, $currentScope, $value); } - } + }, ); $processor->mapConfigArray('content_type_handlers', $config); diff --git a/bundle/Handler/FieldType/Handler.php b/bundle/Handler/FieldType/Handler.php index 139552d..749c309 100644 --- a/bundle/Handler/FieldType/Handler.php +++ b/bundle/Handler/FieldType/Handler.php @@ -27,7 +27,7 @@ public function getMetaTags(string $tagName, array $params = []): array if (!isset($params[0])) { throw new InvalidArgumentException( '$params[0]', - 'Field type handlers require at least a field identifier.' + 'Field type handlers require at least a field identifier.', ); } @@ -49,7 +49,7 @@ public function getMetaTags(string $tagName, array $params = []): array return [ new Item( $tagName, - $fieldValue + $fieldValue, ), ]; } @@ -95,7 +95,7 @@ protected function validateField(string $fieldIdentifier): Field if (!$this->supports($field)) { throw new InvalidArgumentException( '$params[0]', - static::class . ' field type handler does not support field with identifier \'' . $field->fieldDefIdentifier . '\'.' + static::class . ' field type handler does not support field with identifier \'' . $field->fieldDefIdentifier . '\'.', ); } diff --git a/bundle/Handler/FieldType/Image.php b/bundle/Handler/FieldType/Image.php index d7fb871..267562f 100644 --- a/bundle/Handler/FieldType/Image.php +++ b/bundle/Handler/FieldType/Image.php @@ -31,7 +31,7 @@ public function __construct( FieldHelper $fieldHelper, VariationHandler $imageVariationService, RequestStack $requestStack, - ?LoggerInterface $logger = null + ?LoggerInterface $logger = null, ) { parent::__construct($fieldHelper); @@ -57,11 +57,11 @@ protected function getFieldValue(Field $field, string $tagName, array $params = $this->logger->error("Open Graph image handler: Couldn't get variation '{$variationName}' for image with id {$field->value->id}"); } catch (SourceImageNotFoundException $e) { $this->logger->error( - "Open Graph image handler: Couldn't create variation '{$variationName}' for image with id {$field->value->id} because source image can't be found" + "Open Graph image handler: Couldn't create variation '{$variationName}' for image with id {$field->value->id} because source image can't be found", ); } catch (Exception $e) { $this->logger->error( - "Open Graph image handler: Error while getting variation '{$variationName}' for image with id {$field->value->id}: " . $e->getMessage() + "Open Graph image handler: Error while getting variation '{$variationName}' for image with id {$field->value->id}: " . $e->getMessage(), ); } } diff --git a/bundle/Handler/Literal/CanonicalUrl.php b/bundle/Handler/Literal/CanonicalUrl.php index 3a86261..db5e846 100644 --- a/bundle/Handler/Literal/CanonicalUrl.php +++ b/bundle/Handler/Literal/CanonicalUrl.php @@ -32,7 +32,7 @@ public function getMetaTags($tagName, array $params = []): array return [ new Item( $tagName, - $value + $value, ), ]; } diff --git a/bundle/Handler/Literal/Text.php b/bundle/Handler/Literal/Text.php index 47b02c6..10b2b03 100644 --- a/bundle/Handler/Literal/Text.php +++ b/bundle/Handler/Literal/Text.php @@ -15,14 +15,14 @@ public function getMetaTags(string $tagName, array $params = []): array if (!isset($params[0])) { throw new InvalidArgumentException( '$params[0]', - 'Literal text handler requires the text to output.' + 'Literal text handler requires the text to output.', ); } return [ new Item( $tagName, - $params[0] + $params[0], ), ]; } diff --git a/bundle/Handler/Literal/Url.php b/bundle/Handler/Literal/Url.php index 4bf2d7c..dd1548a 100644 --- a/bundle/Handler/Literal/Url.php +++ b/bundle/Handler/Literal/Url.php @@ -27,7 +27,7 @@ public function getMetaTags(string $tagName, array $params = []): array if (!isset($params[0])) { throw new InvalidArgumentException( '$params[0]', - 'Literal URL handler requires the path to output.' + 'Literal URL handler requires the path to output.', ); } @@ -41,7 +41,7 @@ public function getMetaTags(string $tagName, array $params = []): array return [ new Item( $tagName, - $path + $path, ), ]; } diff --git a/bundle/MetaTag/Collector.php b/bundle/MetaTag/Collector.php index 5c88986..c825457 100644 --- a/bundle/MetaTag/Collector.php +++ b/bundle/MetaTag/Collector.php @@ -45,7 +45,7 @@ public function collect(Content $content): array if (isset($contentTypeHandlers[$contentType->identifier])) { $allHandlers = array_merge( $allHandlers['all_content_types'] ?? [], - $contentTypeHandlers[$contentType->identifier] + $contentTypeHandlers[$contentType->identifier], ); } else { $allHandlers = $allHandlers['all_content_types'] ?? []; @@ -62,7 +62,7 @@ public function collect(Content $content): array if (!$metaTag instanceof Item) { throw new LogicException( '\'' . $handler['handler'] . '\' handler returned wrong value.' . - ' Expected \'Netgen\Bundle\OpenGraphBundle\MetaTag\Item\', got \'' . get_class($metaTag) . '\'.' + ' Expected \'Netgen\Bundle\OpenGraphBundle\MetaTag\Item\', got \'' . get_class($metaTag) . '\'.', ); } diff --git a/bundle/Templating/Twig/Extension/NetgenOpenGraphExtension.php b/bundle/Templating/Twig/Extension/NetgenOpenGraphExtension.php index 1c8aa83..1103da5 100644 --- a/bundle/Templating/Twig/Extension/NetgenOpenGraphExtension.php +++ b/bundle/Templating/Twig/Extension/NetgenOpenGraphExtension.php @@ -15,11 +15,11 @@ public function getFunctions(): array new TwigFunction( 'render_netgen_open_graph', [NetgenOpenGraphRuntime::class, 'renderOpenGraphTags'], - ['is_safe' => ['html']] + ['is_safe' => ['html']], ), new TwigFunction( 'get_netgen_open_graph', - [NetgenOpenGraphRuntime::class, 'getOpenGraphTags'] + [NetgenOpenGraphRuntime::class, 'getOpenGraphTags'], ), ]; } diff --git a/bundle/Templating/Twig/Extension/NetgenOpenGraphRuntime.php b/bundle/Templating/Twig/Extension/NetgenOpenGraphRuntime.php index 342b6dd..12a07db 100644 --- a/bundle/Templating/Twig/Extension/NetgenOpenGraphRuntime.php +++ b/bundle/Templating/Twig/Extension/NetgenOpenGraphRuntime.php @@ -24,7 +24,7 @@ final class NetgenOpenGraphRuntime public function __construct( CollectorInterface $tagCollector, RendererInterface $tagRenderer, - ?LoggerInterface $logger = null + ?LoggerInterface $logger = null, ) { $this->tagCollector = $tagCollector; $this->tagRenderer = $tagRenderer; @@ -46,7 +46,7 @@ public function renderOpenGraphTags(Content $content): string { try { return $this->tagRenderer->render( - $this->getOpenGraphTags($content) + $this->getOpenGraphTags($content), ); } catch (Exception $e) { if ($this->throwExceptions) { diff --git a/tests/DependencyInjection/Compiler/MetaTagHandlersCompilerPassTest.php b/tests/DependencyInjection/Compiler/MetaTagHandlersCompilerPassTest.php index a3a076d..83072be 100644 --- a/tests/DependencyInjection/Compiler/MetaTagHandlersCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/MetaTagHandlersCompilerPassTest.php @@ -34,7 +34,7 @@ public function testCompilerPassCollectsValidServices(): void [ 'field_type/eztext', new Reference('handler_one'), - ] + ], ); $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( @@ -43,7 +43,7 @@ public function testCompilerPassCollectsValidServices(): void [ 'literal/text', new Reference('handler_two'), - ] + ], ); } @@ -66,7 +66,7 @@ public function testCompilerPassMustThrowExceptionIfActionServiceDoesNotHaveAlia 'addHandler', [ new Reference('handler_one'), - ] + ], ); } diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 4e2cea4..d21b05b 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -75,7 +75,7 @@ public function testConfigurationValuesAreOkAndValid(): void ], ], ], - ] + ], ); } @@ -142,7 +142,7 @@ public function testConfigurationWithoutRequiredHandlerInContentTypeHandlers(): ], ], ], - 'netgen_open_graph.system.default.content_type_handlers.content_type_one' + 'netgen_open_graph.system.default.content_type_handlers.content_type_one', ); } @@ -210,7 +210,7 @@ public function testConfigurationWithHandlerEmptyInContentTypeHandlers(): void ], ], ], - 'netgen_open_graph.system.default.content_type_handlers.content_type_one' + 'netgen_open_graph.system.default.content_type_handlers.content_type_one', ); } @@ -272,7 +272,7 @@ public function testConfigurationWithoutRequiredTagInContentTypeHandlers(): void ], ], ], - 'netgen_open_graph.system.default.content_type_handlers.content_type_one' + 'netgen_open_graph.system.default.content_type_handlers.content_type_one', ); } @@ -335,7 +335,7 @@ public function testConfigurationWithTagEmptyInContentTypeHandlers(): void ], ], ], - 'netgen_open_graph.system.default.content_type_handlers.content_type_one' + 'netgen_open_graph.system.default.content_type_handlers.content_type_one', ); } @@ -402,7 +402,7 @@ public function testConfigurationWithoutRequiredHandlerInGlobalHandlers(): void ], ], ], - 'netgen_open_graph.system.default.global_handlers' + 'netgen_open_graph.system.default.global_handlers', ); } @@ -470,7 +470,7 @@ public function testConfigurationWithHandlerEmptyInGlobalHandlers(): void ], ], ], - 'netgen_open_graph.system.default.global_handlers' + 'netgen_open_graph.system.default.global_handlers', ); } @@ -537,7 +537,7 @@ public function testConfigurationWithoutRequiredTagInGlobalHandlers(): void ], ], ], - 'netgen_open_graph.system.default.global_handlers' + 'netgen_open_graph.system.default.global_handlers', ); } @@ -605,7 +605,7 @@ public function testConfigurationWithTagEmptyInGlobalHandlers(): void ], ], ], - 'netgen_open_graph.system.default.global_handlers' + 'netgen_open_graph.system.default.global_handlers', ); } diff --git a/tests/Handler/Literal/UrlTest.php b/tests/Handler/Literal/UrlTest.php index c4bff69..73b61ab 100644 --- a/tests/Handler/Literal/UrlTest.php +++ b/tests/Handler/Literal/UrlTest.php @@ -54,7 +54,7 @@ public function testGettingTagsWithValidResult(string $input, string $output): v self::assertSame($output, $result[0]->getTagValue()); } - public function validResultProvider(): array + public function validResultProvider(): iterable { return [ ['https://other.domain.com/some/path', 'https://other.domain.com/some/path'], @@ -79,7 +79,7 @@ public function testGettingTagsWithValidResultAndWithoutRequest(string $input, s self::assertSame($output, $result[0]->getTagValue()); } - public function validResultProviderWithoutRequest(): array + public function validResultProviderWithoutRequest(): iterable { return [ ['https://other.domain.com/some/path', 'https://other.domain.com/some/path'], diff --git a/tests/MetaTag/CollectorTest.php b/tests/MetaTag/CollectorTest.php index bc6b967..b43d90e 100644 --- a/tests/MetaTag/CollectorTest.php +++ b/tests/MetaTag/CollectorTest.php @@ -82,15 +82,15 @@ public function testCollect(): void [ 'id' => 123, 'contentTypeId' => 42, - ] + ], ), - ] + ], ); $content = new Content( [ 'versionInfo' => $versionInfo, - ] + ], ); $contentType = new ContentType( @@ -103,10 +103,10 @@ public function testCollect(): void 'id' => 'id', 'identifier' => 'name', 'fieldTypeIdentifier' => 'eztext', - ] + ], ), ], - ] + ], ); $this->contentTypeService->expects(self::once()) @@ -154,15 +154,15 @@ public function testCollectWithLogicException(): void [ 'id' => 123, 'contentTypeId' => 42, - ] + ], ), - ] + ], ); $content = new Content( [ 'versionInfo' => $versionInfo, - ] + ], ); $contentType = new ContentType( @@ -175,10 +175,10 @@ public function testCollectWithLogicException(): void 'id' => 'id', 'identifier' => 'name', 'fieldTypeIdentifier' => 'eztext', - ] + ], ), ], - ] + ], ); $this->contentTypeService->expects(self::once()) diff --git a/tests/Stubs/Handler.php b/tests/Stubs/Handler.php index 190ef39..25b379c 100644 --- a/tests/Stubs/Handler.php +++ b/tests/Stubs/Handler.php @@ -14,7 +14,7 @@ public function getMetaTags(string $tagName, array $params = []): array return [ new Item( 'og:type', - 'article' + 'article', ), ]; } diff --git a/tests/Templating/Twig/Extension/NetgenOpenGraphExtensionTwigTest.php b/tests/Templating/Twig/Extension/NetgenOpenGraphExtensionTwigTest.php index b521bce..2480858 100644 --- a/tests/Templating/Twig/Extension/NetgenOpenGraphExtensionTwigTest.php +++ b/tests/Templating/Twig/Extension/NetgenOpenGraphExtensionTwigTest.php @@ -79,7 +79,7 @@ protected function getRuntimeLoaders(): array new FactoryRuntimeLoader( [ NetgenOpenGraphRuntime::class => fn (): NetgenOpenGraphRuntime => $this->runtime, - ] + ], ), ]; }