Skip to content

Commit

Permalink
Update CS rules
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Dec 7, 2023
1 parent 96e00b8 commit 702c515
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 51 deletions.
18 changes: 13 additions & 5 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

declare(strict_types=1);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PER' => true,
'@PER:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,

Expand All @@ -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
Expand All @@ -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'])
)
;
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}

Expand All @@ -32,7 +32,7 @@ public function process(ContainerBuilder $container): void
[
$tag['alias'],
new Reference($serviceId),
]
],
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/DependencyInjection/NetgenOpenGraphExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions bundle/Handler/FieldType/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}

Expand All @@ -49,7 +49,7 @@ public function getMetaTags(string $tagName, array $params = []): array
return [
new Item(
$tagName,
$fieldValue
$fieldValue,
),
];
}
Expand Down Expand Up @@ -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 . '\'.',
);
}

Expand Down
6 changes: 3 additions & 3 deletions bundle/Handler/FieldType/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
FieldHelper $fieldHelper,
VariationHandler $imageVariationService,
RequestStack $requestStack,
?LoggerInterface $logger = null
?LoggerInterface $logger = null,
) {
parent::__construct($fieldHelper);

Expand All @@ -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(),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/Handler/Literal/CanonicalUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getMetaTags($tagName, array $params = []): array
return [
new Item(
$tagName,
$value
$value,
),
];
}
Expand Down
4 changes: 2 additions & 2 deletions bundle/Handler/Literal/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
),
];
}
Expand Down
4 changes: 2 additions & 2 deletions bundle/Handler/Literal/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}

Expand All @@ -41,7 +41,7 @@ public function getMetaTags(string $tagName, array $params = []): array
return [
new Item(
$tagName,
$path
$path,
),
];
}
Expand Down
4 changes: 2 additions & 2 deletions bundle/MetaTag/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? [];
Expand All @@ -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) . '\'.',
);
}

Expand Down
4 changes: 2 additions & 2 deletions bundle/Templating/Twig/Extension/NetgenOpenGraphExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
),
];
}
Expand Down
4 changes: 2 additions & 2 deletions bundle/Templating/Twig/Extension/NetgenOpenGraphRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testCompilerPassCollectsValidServices(): void
[
'field_type/eztext',
new Reference('handler_one'),
]
],
);

$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
Expand All @@ -43,7 +43,7 @@ public function testCompilerPassCollectsValidServices(): void
[
'literal/text',
new Reference('handler_two'),
]
],
);
}

Expand All @@ -66,7 +66,7 @@ public function testCompilerPassMustThrowExceptionIfActionServiceDoesNotHaveAlia
'addHandler',
[
new Reference('handler_one'),
]
],
);
}

Expand Down
18 changes: 9 additions & 9 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testConfigurationValuesAreOkAndValid(): void
],
],
],
]
],
);
}

Expand Down Expand Up @@ -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',
);
}

Expand Down Expand Up @@ -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',
);
}

Expand Down Expand Up @@ -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',
);
}

Expand Down Expand Up @@ -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',
);
}

Expand Down Expand Up @@ -402,7 +402,7 @@ public function testConfigurationWithoutRequiredHandlerInGlobalHandlers(): void
],
],
],
'netgen_open_graph.system.default.global_handlers'
'netgen_open_graph.system.default.global_handlers',
);
}

Expand Down Expand Up @@ -470,7 +470,7 @@ public function testConfigurationWithHandlerEmptyInGlobalHandlers(): void
],
],
],
'netgen_open_graph.system.default.global_handlers'
'netgen_open_graph.system.default.global_handlers',
);
}

Expand Down Expand Up @@ -537,7 +537,7 @@ public function testConfigurationWithoutRequiredTagInGlobalHandlers(): void
],
],
],
'netgen_open_graph.system.default.global_handlers'
'netgen_open_graph.system.default.global_handlers',
);
}

Expand Down Expand Up @@ -605,7 +605,7 @@ public function testConfigurationWithTagEmptyInGlobalHandlers(): void
],
],
],
'netgen_open_graph.system.default.global_handlers'
'netgen_open_graph.system.default.global_handlers',
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Handler/Literal/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand Down
Loading

0 comments on commit 702c515

Please sign in to comment.