Skip to content

Commit 598ce15

Browse files
committed
[TASK] Sync rule with the Core and switch to @PER-CS3x0
Adapt https://review.typo3.org/c/Packages/TYPO3.CMS/+/93890 for our template and our own configuration. Also fix our own code with the new ruleset.
1 parent 65d8d19 commit 598ce15

26 files changed

Lines changed: 164 additions & 145 deletions

.php-cs-fixer.dist.php

Lines changed: 82 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<<<EOM
77
This file is part of the TYPO3 project.
88
9-
(c) 2019-2024 Benni Mack
9+
(c) 2019-2026 Benni Mack
1010
Simon Gilli
1111
1212
For the full copyright and license information, please view
@@ -17,55 +17,98 @@
1717
true
1818
)
1919
->addRules([
20-
'@PER:risky' => true,
21-
'@PHP80Migration:risky' => true,
22-
'@PHP81Migration' => true,
23-
'declare_strict_types' => true,
24-
'fully_qualified_strict_types' => true,
20+
'@DoctrineAnnotation' => true,
21+
'@PER-CS3x0' => true,
22+
// Override PER-CS3x0 default (single) to keep no space after cast operators
23+
'cast_spaces' => ['space' => 'none'],
24+
'declare_parentheses' => true,
25+
'dir_constant' => true,
26+
'function_to_constant' => [
27+
'functions' => [
28+
'get_called_class',
29+
'get_class',
30+
'get_class_this',
31+
'php_sapi_name',
32+
'phpversion',
33+
'pi',
34+
],
35+
],
36+
'type_declaration_spaces' => true,
2537
'global_namespace_import' => [
26-
'import_classes' => true,
38+
'import_classes' => false,
2739
'import_constants' => false,
2840
'import_functions' => false,
2941
],
30-
'no_unneeded_import_alias' => true,
31-
'ordered_imports' => [
32-
'imports_order' => ['class', 'function', 'const'],
33-
'sort_algorithm' => 'alpha',
42+
'list_syntax' => ['syntax' => 'short'],
43+
'modernize_strpos' => true,
44+
'modernize_types_casting' => true,
45+
'native_function_casing' => true,
46+
'native_function_invocation' => [
47+
'include' => [],
48+
'scope' => 'all',
49+
'strict' => true,
3450
],
35-
'phpdoc_align' => true,
36-
'phpdoc_annotation_without_dot' => true,
37-
'phpdoc_indent' => true,
38-
'phpdoc_inline_tag_normalizer' => true,
39-
'phpdoc_line_span' => true,
40-
'phpdoc_no_useless_inheritdoc' => true,
41-
'phpdoc_order' => true,
42-
'phpdoc_order_by_value' => true,
43-
'phpdoc_separation' => true,
44-
'phpdoc_single_line_var_spacing' => true,
45-
'phpdoc_summary' => true,
46-
'phpdoc_tag_casing' => true,
47-
'phpdoc_tag_type' => true,
48-
'phpdoc_to_comment' => [
49-
'ignored_tags' => [
50-
'phpstan-ignore-line',
51-
'phpstan-ignore-next-line',
52-
'todo',
53-
],
51+
'no_alias_functions' => true,
52+
'no_blank_lines_after_phpdoc' => true,
53+
'no_empty_phpdoc' => true,
54+
'no_empty_statement' => true,
55+
'no_extra_blank_lines' => true,
56+
'no_leading_namespace_whitespace' => true,
57+
'no_null_property_initialization' => true,
58+
'no_short_bool_cast' => true,
59+
'no_singleline_whitespace_before_semicolons' => true,
60+
'no_superfluous_elseif' => true,
61+
'no_trailing_comma_in_singleline' => true,
62+
'no_unneeded_control_parentheses' => true,
63+
'no_unused_imports' => true,
64+
'no_useless_else' => true,
65+
'no_useless_nullsafe_operator' => true,
66+
// Override PER-CS3x0 default (union) to keep ?Type shorthand syntax
67+
'nullable_type_declaration' => [
68+
'syntax' => 'question_mark',
5469
],
55-
'phpdoc_trim_consecutive_blank_line_separation' => true,
56-
'phpdoc_types_order' => [
57-
'null_adjustment' => 'always_last',
58-
'sort_algorithm' => 'alpha',
70+
'nullable_type_declaration_for_default_null_value' => true,
71+
'ordered_class_elements' => ['order' => ['use_trait', 'case', 'constant', 'property']],
72+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
73+
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
74+
'php_unit_mock_short_will_return' => true,
75+
'php_unit_test_case_static_method_calls' => [
76+
'call_type' => 'self',
77+
'methods' => [
78+
'any' => 'this',
79+
'atLeast' => 'this',
80+
'atLeastOnce' => 'this',
81+
'atMost' => 'this',
82+
'exactly' => 'this',
83+
'never' => 'this',
84+
'onConsecutiveCalls' => 'this',
85+
'once' => 'this',
86+
'returnArgument' => 'this',
87+
'returnCallback' => 'this',
88+
'returnSelf' => 'this',
89+
'returnValue' => 'this',
90+
'returnValueMap' => 'this',
91+
'throwException' => 'this',
92+
],
5993
],
60-
'phpdoc_var_annotation_correct_order' => true,
61-
'phpdoc_var_without_name' => true,
62-
'self_accessor' => true,
94+
'phpdoc_no_access' => true,
95+
'phpdoc_no_empty_return' => true,
96+
'phpdoc_no_package' => true,
97+
'phpdoc_scalar' => true,
98+
'phpdoc_trim' => true,
99+
'phpdoc_types' => true,
100+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
101+
'protected_to_private' => true,
102+
'single_quote' => true,
103+
'single_line_comment_style' => ['comment_types' => ['hash']],
104+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
105+
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
106+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
63107
])
64108
->getFinder()
65109
->exclude('templates')
66110
->exclude('tests/Unit/Fixtures')
67111
->in(__DIR__)
68-
->append(['typo3-coding-standards'])
69-
;
112+
->append(['typo3-coding-standards']);
70113

71114
return $config;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"require": {
3333
"php": "^8.1",
3434
"ext-json": "*",
35-
"friendsofphp/php-cs-fixer": "^3.88.2",
35+
"friendsofphp/php-cs-fixer": "^3.95.1",
3636
"symfony/console": "^6.4 || ^7.0",
3737
"symfony/filesystem": "^6.4 || ^7.0"
3838
},

rector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* This file is part of the TYPO3 project.
77
*
8-
* (c) 2019-2024 Benni Mack
8+
* (c) 2019-2026 Benni Mack
99
* Simon Gilli
1010
*
1111
* For the full copyright and license information, please view

src/Console/Application.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* This file is part of the TYPO3 project.
77
*
8-
* (c) 2019-2024 Benni Mack
8+
* (c) 2019-2026 Benni Mack
99
* Simon Gilli
1010
*
1111
* For the full copyright and license information, please view
@@ -16,7 +16,6 @@
1616

1717
namespace TYPO3\CodingStandards\Console;
1818

19-
use RuntimeException;
2019
use Symfony\Component\Console\Application as BaseApplication;
2120
use Symfony\Component\Console\Input\InputDefinition;
2221
use Symfony\Component\Console\Input\InputInterface;
@@ -38,7 +37,7 @@ final class Application extends BaseApplication
3837
/**
3938
* getcwd() equivalent which always returns a string.
4039
*
41-
* @throws RuntimeException
40+
* @throws \RuntimeException
4241
*/
4342
private static function getCwd(bool $allowEmpty = false): string
4443
{
@@ -57,7 +56,7 @@ private static function getCwd(bool $allowEmpty = false): string
5756
return '';
5857
}
5958

60-
throw new RuntimeException('Could not determine the current working directory');
59+
throw new \RuntimeException('Could not determine the current working directory');
6160
}
6261

6362
// @codeCoverageIgnoreEnd
@@ -71,7 +70,7 @@ public static function getProjectDir(): string
7170
}
7271

7372
/**
74-
* @throws RuntimeException
73+
* @throws \RuntimeException
7574
*/
7675
public static function getTargetDir(InputInterface $input): string
7776
{
@@ -87,7 +86,7 @@ public static function getTargetDir(InputInterface $input): string
8786
}
8887

8988
if (!is_dir($targetDir)) {
90-
throw new RuntimeException(\sprintf('Invalid target directory specified, %s does not exist.', $targetDir));
89+
throw new \RuntimeException(sprintf('Invalid target directory specified, %s does not exist.', $targetDir));
9190
}
9291

9392
return $targetDir;

src/Console/Command/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* This file is part of the TYPO3 project.
77
*
8-
* (c) 2019-2024 Benni Mack
8+
* (c) 2019-2026 Benni Mack
99
* Simon Gilli
1010
*
1111
* For the full copyright and license information, please view

src/Console/Command/SetupCommand.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* This file is part of the TYPO3 project.
77
*
8-
* (c) 2019-2024 Benni Mack
8+
* (c) 2019-2026 Benni Mack
99
* Simon Gilli
1010
*
1111
* For the full copyright and license information, please view
@@ -16,7 +16,6 @@
1616

1717
namespace TYPO3\CodingStandards\Console\Command;
1818

19-
use RuntimeException;
2019
use Symfony\Component\Console\Input\InputArgument;
2120
use Symfony\Component\Console\Input\InputInterface;
2221
use Symfony\Component\Console\Input\InputOption;
@@ -73,7 +72,7 @@ private function getRuleSets(InputInterface $input): array
7372
}
7473

7574
/**
76-
* @throws RuntimeException
75+
* @throws \RuntimeException
7776
*/
7877
private function getType(InputInterface $input): string
7978
{
@@ -84,22 +83,22 @@ private function getType(InputInterface $input): string
8483

8584
$composerManifest = $this->getProjectDir() . '/composer.json';
8685
if (!file_exists($composerManifest)) {
87-
throw new RuntimeException(sprintf($composerManifestError, 'found'));
86+
throw new \RuntimeException(sprintf($composerManifestError, 'found'));
8887
}
8988

90-
$composerManifest = \file_get_contents($composerManifest);
89+
$composerManifest = file_get_contents($composerManifest);
9190
if ($composerManifest === false) {
92-
throw new RuntimeException(sprintf($composerManifestError, 'read')); // @codeCoverageIgnore
91+
throw new \RuntimeException(sprintf($composerManifestError, 'read')); // @codeCoverageIgnore
9392
}
9493

95-
$composerManifest = \json_decode($composerManifest, true);
94+
$composerManifest = json_decode($composerManifest, true);
9695
if ($composerManifest === false || !is_array($composerManifest)) {
97-
throw new RuntimeException(sprintf($composerManifestError, 'decoded'));
96+
throw new \RuntimeException(sprintf($composerManifestError, 'decoded'));
9897
}
9998

10099
if (
101-
($composerManifest['type'] ?? '') === 'typo3-cms-extension' ||
102-
($composerManifest['extra']['typo3/cms']['extension-key'] ?? '') !== ''
100+
($composerManifest['type'] ?? '') === 'typo3-cms-extension'
101+
|| ($composerManifest['extra']['typo3/cms']['extension-key'] ?? '') !== ''
103102
) {
104103
$type = Setup::EXTENSION;
105104
} else {
@@ -120,11 +119,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
120119

121120
$result = true;
122121

123-
if (\in_array(Setup::RULE_SET_EDITORCONFIG, $ruleSets, true)) {
122+
if (in_array(Setup::RULE_SET_EDITORCONFIG, $ruleSets, true)) {
124123
$result = $setup->copyEditorConfig($force);
125124
}
126125

127-
if (\in_array(Setup::RULE_SET_PHP_CS_FIXER, $ruleSets, true)) {
126+
if (in_array(Setup::RULE_SET_PHP_CS_FIXER, $ruleSets, true)) {
128127
$result = $setup->copyPhpCsFixerConfig($force, $type) && $result;
129128
}
130129

src/Console/Command/UpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* This file is part of the TYPO3 project.
77
*
8-
* (c) 2019-2024 Benni Mack
8+
* (c) 2019-2026 Benni Mack
99
* Simon Gilli
1010
*
1111
* For the full copyright and license information, please view

src/CsFixerConfig.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* This file is part of the TYPO3 project.
77
*
8-
* (c) 2019-2024 Benni Mack
8+
* (c) 2019-2026 Benni Mack
99
* Simon Gilli
1010
*
1111
* For the full copyright and license information, please view
@@ -41,20 +41,11 @@ class CsFixerConfig extends Config implements CsFixerConfigInterface
4141
*/
4242
protected static $typo3Rules = [
4343
'@DoctrineAnnotation' => true,
44-
// @todo: Switch to @PER-CS2x0 once php-cs-fixer's todo list is done: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7247
45-
'@PER-CS1x0' => true,
46-
'array_indentation' => true,
47-
'array_syntax' => ['syntax' => 'short'],
44+
'@PER-CS3x0' => true,
45+
// Override PER-CS3x0 default (single) to keep no space after cast operators
4846
'cast_spaces' => ['space' => 'none'],
49-
// @todo: Can be dropped once we enable @PER-CS2x0
50-
'concat_space' => ['spacing' => 'one'],
51-
'declare_equal_normalize' => ['space' => 'none'],
5247
'declare_parentheses' => true,
5348
'dir_constant' => true,
54-
// @todo: Can be dropped once we enable @PER-CS2x0
55-
'function_declaration' => [
56-
'closure_fn_spacing' => 'none',
57-
],
5849
'function_to_constant' => [
5950
'functions' => [
6051
'get_called_class',
@@ -72,8 +63,6 @@ class CsFixerConfig extends Config implements CsFixerConfigInterface
7263
'import_functions' => false,
7364
],
7465
'list_syntax' => ['syntax' => 'short'],
75-
// @todo: Can be dropped once we enable @PER-CS2x0
76-
'method_argument_space' => true,
7766
'modernize_strpos' => true,
7867
'modernize_types_casting' => true,
7968
'native_function_casing' => true,
@@ -97,6 +86,7 @@ class CsFixerConfig extends Config implements CsFixerConfigInterface
9786
'no_unused_imports' => true,
9887
'no_useless_else' => true,
9988
'no_useless_nullsafe_operator' => true,
89+
// Override PER-CS3x0 default (union) to keep ?Type shorthand syntax
10090
'nullable_type_declaration' => [
10191
'syntax' => 'question_mark',
10292
],
@@ -132,12 +122,8 @@ class CsFixerConfig extends Config implements CsFixerConfigInterface
132122
'phpdoc_types' => true,
133123
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
134124
'protected_to_private' => true,
135-
'return_type_declaration' => ['space_before' => 'none'],
136125
'single_quote' => true,
137-
'single_space_around_construct' => true,
138126
'single_line_comment_style' => ['comment_types' => ['hash']],
139-
// @todo: Can be dropped once we enable @PER-CS2x0
140-
'single_line_empty_body' => true,
141127
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
142128
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
143129
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],

src/CsFixerConfigInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* This file is part of the TYPO3 project.
77
*
8-
* (c) 2019-2024 Benni Mack
8+
* (c) 2019-2026 Benni Mack
99
* Simon Gilli
1010
*
1111
* For the full copyright and license information, please view

0 commit comments

Comments
 (0)