Skip to content

Commit

Permalink
[TASK] Update code style definition and apply fixers
Browse files Browse the repository at this point in the history
  • Loading branch information
garfieldius committed Dec 15, 2023
1 parent d25badb commit f216ae4
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 93 deletions.
126 changes: 105 additions & 21 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,111 @@

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . DIRECTORY_SEPARATOR . 'Tests')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'Classes');
use Symfony\Component\Finder\Finder;

$config = new PhpCsFixer\Config();
$finder = Finder::create()
->in(__DIR__)
->notPath('Build')
->notPath('Documentation')
->notPath('Resources')
->notPath('vendor');

return $config->setUsingCache(true)->setRiskyAllowed(true)->setRules([
'@PSR12' => true,
'array_indentation' => true,
'no_unused_imports' => true,
'cast_spaces' => ['space' => 'none'],
'no_extra_blank_lines' => [
'tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use'],
],
'types_spaces' => ['space' => 'single'],
'binary_operator_spaces' => [
'operators' => [
'|' => 'no_space',
'=>' => 'align',
],
],
'no_trailing_comma_in_singleline_array' => true,
])
return (new PhpCsFixer\Config())
->setUsingCache(true)
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'@PSR12' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'align_multiline_comment' => [
'comment_type' => 'phpdocs_like',
],
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => 'align_single_space_minimal',
],
],
'blank_line_before_statement' => [
'statements' => ['if', 'try', 'return'],
],
'cast_spaces' => ['space' => 'none'],
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'declare_strict_types' => true,
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'dir_constant' => true,
'ereg_to_preg' => true,
'escape_implicit_backslashes' => [
'double_quoted' => true,
'heredoc_syntax' => true,
'single_quoted' => true,
],
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'type_declaration_spaces' => ['elements' => ['function', 'property']],
'linebreak_after_opening_tag' => true,
'lowercase_cast' => true,
'magic_constant_casing' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'new_with_parentheses' => [
'anonymous_class' => true,
'named_class' => true,
],
'no_alias_functions' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => [
'use' => 'echo',
],
'no_multiline_whitespace_around_double_arrow' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_spaces_after_function_name' => true,
'no_spaces_around_offset' => [
'positions' => ['inside', 'outside'],
],
'spaces_inside_parentheses' => ['space' => 'none'],
'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_in_blank_line' => true,
'non_printable_character' => false,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_indent' => true,
'phpdoc_scalar' => true,
'short_scalar_cast' => true,
'single_line_comment_style' => true,
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'single_quote' => [
'strings_containing_single_quote_chars' => true,
],
'standardize_not_equals' => true,
'visibility_required' => true,
'ternary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
])
->setFinder($finder);
12 changes: 6 additions & 6 deletions Classes/CSP/SupiPolicyExtender.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class SupiPolicyExtender implements SingletonInterface
{
private array $extensions = [];

public function addInlineScript(string $data): void
{
$hash = hash('sha256', $data);
$this->extensions[] = [Directive::ScriptSrc, new HashValue($hash)];
}

public function __invoke(PolicyMutatedEvent $event): void
{
foreach ($this->extensions as $extension) {
$event->getCurrentPolicy()->extend(...$extension);
}
}

public function addInlineScript(string $data): void
{
$hash = hash('sha256', $data);
$this->extensions[] = [Directive::ScriptSrc, new HashValue($hash)];
}
}
2 changes: 1 addition & 1 deletion Classes/DataProcessing/AddressProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
$address = $cObj->data[$processorConfiguration['field'] ?? 'bodytext'] ?? '';

if (str_contains($address, ',')) {
$address = GeneralUtility::trimExplode(",", $address, true);
$address = GeneralUtility::trimExplode(',', $address, true);
} else {
$address = GeneralUtility::trimExplode("\n", $address, true);
}
Expand Down
1 change: 1 addition & 0 deletions Classes/DataProcessing/SpotifyProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
$url = ($processedData['settings']['spotify']['url'] ?? '') ?: 'https://open.spotify.com/embed/playlist/{id}';
$vals['src'] = str_replace('{id}', $id, $url);
$processedData[$as] = json_encode($vals, JSON_FORCE_OBJECT);

return $processedData;
}
}
2 changes: 1 addition & 1 deletion Classes/DataProcessing/YoutubeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
}

foreach (GeneralUtility::trimExplode("\n", $cObj->data[$processorConfiguration['urlsField'] ?? 'tx_supi_youtube_urls'] ?? '', true) as $url) {
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);
preg_match('%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^"&?/ ]{11})%i', $url, $match);

if (is_array($match) && !empty($match[1])) {
$videoId = $match[1];
Expand Down
5 changes: 4 additions & 1 deletion Configuration/Icons.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

return [
'supi' => [
'provider' => \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
'source' => 'EXT:supi/Resources/Public/Icons/Extension.svg',
'source' => 'EXT:supi/Resources/Public/Icons/Extension.svg',
],
];
12 changes: 6 additions & 6 deletions Configuration/TCA/Overrides/sys_file_reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

declare(strict_types=1);

(function ($extKey, $table) {
(function ($extKey, $table): void {
$ll = 'LLL:EXT:supi/Resources/Private/Language/locallang_db.xlf:';

/**
* Additional columns
*/
$additionalColumns = [
'tx_supi_video_cover' => [
'label' => $ll . $table . '.tx_supi_video_cover.label',
'description' => $ll . $table . '.tx_supi_video_cover.description',
'config' => [
'type' => 'file',
'label' => $ll . $table . '.tx_supi_video_cover.label',
'description' => $ll . $table . '.tx_supi_video_cover.description',
'config' => [
'type' => 'file',
'maxitems' => 1,
'allowed' => ['jpg', 'jpeg', 'png', 'svg'],
'allowed' => ['jpg', 'jpeg', 'png', 'svg'],
],
],
];
Expand Down
Loading

0 comments on commit f216ae4

Please sign in to comment.