From 847a74830b62ccfb87c3b02bf701904eeb9791c9 Mon Sep 17 00:00:00 2001 From: Christian Kuhn Date: Mon, 30 Oct 2023 12:30:23 +0100 Subject: [PATCH] [TASK] Bump friendsofphp/php-cs-fixer:^3.37.1 (#515) Also align rules with core > composer req --dev friendsofphp/php-cs-fixer:^3.37.1 > Build/Scripts/runTests.sh -p 8.1 -s cgl Releases: main, 7 --- Build/php-cs-fixer/config.php | 35 ++++++++++++------- Classes/Composer/ComposerPackageManager.php | 6 ++-- Classes/Composer/PackageInfo.php | 9 +++-- .../Extension/BackendEnvironment.php | 1 + .../Acceptance/Helper/AbstractModalDialog.php | 1 + .../Acceptance/Helper/AbstractPageTree.php | 4 +-- Classes/Core/Acceptance/Helper/Acceptance.php | 1 + Classes/Core/Acceptance/Helper/Login.php | 1 + Classes/Core/Acceptance/Helper/Topbar.php | 1 + Classes/Core/Acceptance/Step/FrameSteps.php | 1 + Classes/Core/AccessibleProxyTrait.php | 1 + Classes/Core/BaseTestCase.php | 3 +- Classes/Core/Exception.php | 5 ++- .../AbstractRecordConstraint.php | 5 +-- .../AbstractStructureRecordConstraint.php | 1 + .../DoesNotHaveRecordConstraint.php | 1 + .../RequestSection/HasRecordConstraint.php | 1 + .../StructureDoesNotHaveRecordConstraint.php | 1 + .../StructureHasRecordConstraint.php | 1 + .../Framework/DataHandling/ActionService.php | 7 ++-- .../Scenario/DataHandlerFactory.php | 3 +- .../Scenario/DataHandlerWriter.php | 9 ++--- .../Scenario/EntityConfiguration.php | 1 + .../Snapshot/DatabaseSnapshot.php | 2 +- .../Functional/Framework/FrameworkState.php | 1 + .../Functional/Framework/Frontend/Parser.php | 1 + .../Framework/Frontend/Renderer.php | 1 + .../Framework/Frontend/ResponseContent.php | 5 ++- .../Core/Functional/FunctionalTestCase.php | 2 +- Classes/Core/PackageCollection.php | 6 ++-- Classes/Core/Testbase.php | 10 +++--- Classes/Core/Unit/UnitTestCase.php | 6 ++-- composer.json | 2 +- 33 files changed, 81 insertions(+), 54 deletions(-) diff --git a/Build/php-cs-fixer/config.php b/Build/php-cs-fixer/config.php index a011fbc2..57ebfa08 100644 --- a/Build/php-cs-fixer/config.php +++ b/Build/php-cs-fixer/config.php @@ -19,27 +19,33 @@ ->setRiskyAllowed(true) ->setRules([ '@DoctrineAnnotation' => true, - '@PSR2' => true, + // @todo: Switch to @PER-CS2.0 once php-cs-fixer's todo list is done: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7247 + '@PER-CS1.0' => true, 'array_syntax' => ['syntax' => 'short'], - 'blank_line_after_opening_tag' => true, - 'braces' => ['allow_single_line_closure' => true], 'cast_spaces' => ['space' => 'none'], - 'compact_nullable_typehint' => true, + // @todo: Can be dropped once we enable @PER-CS2.0 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], + 'declare_parentheses' => true, 'dir_constant' => true, - 'function_typehint_space' => true, - 'lowercase_cast' => true, - 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], + // @todo: Can be dropped once we enable @PER-CS2.0 + 'function_declaration' => [ + 'closure_fn_spacing' => 'none', + ], + 'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']], + 'type_declaration_spaces' => true, + 'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false], + 'list_syntax' => ['syntax' => 'short'], + // @todo: Can be dropped once we enable @PER-CS2.0 + 'method_argument_space' => true, + 'modernize_strpos' => true, 'modernize_types_casting' => true, 'native_function_casing' => true, - 'new_with_braces' => true, 'no_alias_functions' => true, 'no_blank_lines_after_phpdoc' => 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_null_property_initialization' => true, 'no_short_bool_cast' => true, @@ -49,8 +55,8 @@ 'no_unneeded_control_parentheses' => true, 'no_unused_imports' => true, 'no_useless_else' => true, - 'no_whitespace_in_blank_line' => true, - 'ordered_imports' => true, + 'no_useless_nullsafe_operator' => true, + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'], 'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']], 'php_unit_mock_short_will_return' => true, 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], @@ -63,8 +69,11 @@ 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], 'return_type_declaration' => ['space_before' => 'none'], 'single_quote' => true, + 'single_space_around_construct' => true, 'single_line_comment_style' => ['comment_types' => ['hash']], - 'single_trait_insert_per_statement' => true, + // @todo: Can be dropped once we enable @PER-CS2.0 + 'single_line_empty_body' => true, 'trailing_comma_in_multiline' => ['elements' => ['arrays']], - 'whitespace_after_comma_in_array' => true, + 'whitespace_after_comma_in_array' => ['ensure_single_space' => true], + 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], ]); diff --git a/Classes/Composer/ComposerPackageManager.php b/Classes/Composer/ComposerPackageManager.php index 060b8067..c06015af 100644 --- a/Classes/Composer/ComposerPackageManager.php +++ b/Classes/Composer/ComposerPackageManager.php @@ -266,7 +266,7 @@ private function getPackageFromPath(string $path): ?PackageInfo */ private function processMonoRepository(): void { - if (! ($this->rootPackage()?->isMonoRepository() ?? false)) { + if (!($this->rootPackage()?->isMonoRepository() ?? false)) { return; } @@ -374,7 +374,7 @@ private function getPackageComposerJson(string $path): ?array } try { return json_decode((string)file_get_contents($composerFile), true, JSON_THROW_ON_ERROR); - } catch(\Throwable) { + } catch (\Throwable) { // skipped } return null; @@ -490,7 +490,7 @@ private function split(string $path): array if (str_starts_with($path, '/')) { $root .= '/'; $path = $length > 1 ? substr($path, 1) : ''; - } elseif ($length > 1 && ctype_alpha($path[0]) && ':' === $path[1]) { + } elseif ($length > 1 && ctype_alpha($path[0]) && $path[1] === ':') { if ($length === 2) { // Windows special case: "C:" $root .= $path . '/'; diff --git a/Classes/Composer/PackageInfo.php b/Classes/Composer/PackageInfo.php index 6cc5c0f8..8c84ed9a 100644 --- a/Classes/Composer/PackageInfo.php +++ b/Classes/Composer/PackageInfo.php @@ -31,8 +31,7 @@ public function __construct( private readonly string $extensionKey, private readonly ?array $info = null, private readonly ?array $extEmConf = null, - ) { - } + ) {} public function getName(): string { @@ -96,12 +95,12 @@ public function getExtensionKey(): string public function getVendorDir(): string { - return (string)($this?->info['config']['vendor-dir'] ?? ''); + return (string)($this->info['config']['vendor-dir'] ?? ''); } public function getWebDir(): string { - return (string)($this?->info['extra']['typo3/cms']['web-dir'] ?? ''); + return (string)($this->info['extra']['typo3/cms']['web-dir'] ?? ''); } /** @@ -113,7 +112,7 @@ public function getReplacesPackageNames(): array if ($this->isMonoRepository()) { // Monorepo root composer.json replaces core system extension. We do not want that happen, so // ignore only replaced core extensions. - $keys = array_filter($keys, static fn ($value) => !str_starts_with($value, 'typo3/cms-')); + $keys = array_filter($keys, static fn($value) => !str_starts_with($value, 'typo3/cms-')); } return $keys; } diff --git a/Classes/Core/Acceptance/Extension/BackendEnvironment.php b/Classes/Core/Acceptance/Extension/BackendEnvironment.php index 2d622ad0..1d677a2e 100644 --- a/Classes/Core/Acceptance/Extension/BackendEnvironment.php +++ b/Classes/Core/Acceptance/Extension/BackendEnvironment.php @@ -1,6 +1,7 @@ values; foreach ($records as $recordIdentifier => $recordData) { - if (strpos($recordIdentifier, $this->table . ':') !== 0) { + if (!str_starts_with($recordIdentifier, $this->table . ':')) { continue; } if (isset($recordData[$this->field]) @@ -131,7 +132,7 @@ protected function getRemainingRecords(array $records) $values = $this->values; foreach ($records as $recordIdentifier => $recordData) { - if (strpos($recordIdentifier, $this->table . ':') !== 0) { + if (!str_starts_with($recordIdentifier, $this->table . ':')) { unset($records[$recordIdentifier]); continue; } diff --git a/Classes/Core/Functional/Framework/Constraint/RequestSection/AbstractStructureRecordConstraint.php b/Classes/Core/Functional/Framework/Constraint/RequestSection/AbstractStructureRecordConstraint.php index 717b6844..17368f56 100644 --- a/Classes/Core/Functional/Framework/Constraint/RequestSection/AbstractStructureRecordConstraint.php +++ b/Classes/Core/Functional/Framework/Constraint/RequestSection/AbstractStructureRecordConstraint.php @@ -1,6 +1,7 @@ getUniqueIdForNewRecords(); } - if (strpos((string)$currentUid, 'NEW') === 0) { + if (str_starts_with((string)$currentUid, 'NEW')) { $recordData['pid'] = $pageId; } unset($recordData['uid']); @@ -482,7 +483,7 @@ protected function resolvePreviousUid(array $recordData, $previousUid): array return $recordData; } foreach ($recordData as $fieldName => $fieldValue) { - if (strpos((string)$fieldValue, '__previousUid') === false) { + if (!str_contains((string)$fieldValue, '__previousUid')) { continue; } $recordData[$fieldName] = str_replace('__previousUid', $previousUid, $fieldValue); @@ -501,7 +502,7 @@ protected function resolveNextUid(array $recordData, $nextUid): array return $recordData; } foreach ($recordData as $fieldName => $fieldValue) { - if (is_array($fieldValue) || strpos((string)$fieldValue, '__nextUid') === false) { + if (is_array($fieldValue) || !str_contains((string)$fieldValue, '__nextUid')) { continue; } $recordData[$fieldName] = str_replace('__nextUid', $nextUid, $fieldValue); diff --git a/Classes/Core/Functional/Framework/DataHandling/Scenario/DataHandlerFactory.php b/Classes/Core/Functional/Framework/DataHandling/Scenario/DataHandlerFactory.php index 334a1994..f6738a59 100644 --- a/Classes/Core/Functional/Framework/DataHandling/Scenario/DataHandlerFactory.php +++ b/Classes/Core/Functional/Framework/DataHandling/Scenario/DataHandlerFactory.php @@ -1,6 +1,7 @@ 0) { $previousIndex = $identifiers[$currentIndex - 1]; $values['pid'] = '-' . $identifiers[$previousIndex]; diff --git a/Classes/Core/Functional/Framework/DataHandling/Scenario/DataHandlerWriter.php b/Classes/Core/Functional/Framework/DataHandling/Scenario/DataHandlerWriter.php index e824d051..a3dcbd87 100644 --- a/Classes/Core/Functional/Framework/DataHandling/Scenario/DataHandlerWriter.php +++ b/Classes/Core/Functional/Framework/DataHandling/Scenario/DataHandlerWriter.php @@ -1,6 +1,7 @@ dataHandler->substNEWwithIDs[$value] ?? $value; } - if (strpos($value, '-NEW') === 0) { + if (str_starts_with($value, '-NEW')) { return $this->dataHandler->substNEWwithIDs[substr($value, 1)] ?? $value; } return $value; @@ -151,10 +152,10 @@ function ($value) { if (!is_string($value)) { return $value; } - if (strpos($value, 'NEW') === 0) { + if (str_starts_with($value, 'NEW')) { return $this->dataHandler->substNEWwithIDs[$value] ?? $value; } - if (strpos($value, '-NEW') === 0) { + if (str_starts_with($value, '-NEW')) { return $this->dataHandler->substNEWwithIDs[substr($value, 1)] ?? $value; } return $value; diff --git a/Classes/Core/Functional/Framework/DataHandling/Scenario/EntityConfiguration.php b/Classes/Core/Functional/Framework/DataHandling/Scenario/EntityConfiguration.php index b872b04a..010ce25d 100644 --- a/Classes/Core/Functional/Framework/DataHandling/Scenario/EntityConfiguration.php +++ b/Classes/Core/Functional/Framework/DataHandling/Scenario/EntityConfiguration.php @@ -1,6 +1,7 @@ setTypo3TestingContext(); // See if we're the first test of this test case. - $currentTestCaseClass = get_called_class(); + $currentTestCaseClass = static::class; if (self::$currentTestCaseClass !== $currentTestCaseClass) { self::$currentTestCaseClass = $currentTestCaseClass; } else { diff --git a/Classes/Core/PackageCollection.php b/Classes/Core/PackageCollection.php index be21f9d8..d520d3f9 100644 --- a/Classes/Core/PackageCollection.php +++ b/Classes/Core/PackageCollection.php @@ -63,7 +63,7 @@ public static function fromPackageStates(PackageManager $packageManager, string public function __construct(PackageInterface ...$packages) { $this->packages = array_combine( - array_map(static fn (PackageInterface $package) => $package->getPackageKey(), $packages), + array_map(static fn(PackageInterface $package) => $package->getPackageKey(), $packages), $packages ); } @@ -81,7 +81,7 @@ public function sortPackages(DependencyOrderingService $dependencyOrderingServic $sortedPackageKeys = $this->resolveSortedPackageKeys($dependencyOrderingService); usort( $this->packages, - static fn (PackageInterface $a, PackageInterface $b) => + static fn(PackageInterface $a, PackageInterface $b) => array_search($a->getPackageKey(), $sortedPackageKeys, true) <=> array_search($b->getPackageKey(), $sortedPackageKeys, true) ); @@ -96,7 +96,7 @@ public function sortPackageStates(array $packageStates, DependencyOrderingServic $sortedPackageKeys = $this->resolveSortedPackageKeys($dependencyOrderingService); uksort( $packageStates, - static fn (string $a, string $b) => + static fn(string $a, string $b) => array_search($a, $sortedPackageKeys, true) <=> array_search($b, $sortedPackageKeys, true) ); diff --git a/Classes/Core/Testbase.php b/Classes/Core/Testbase.php index dbf67d8d..a175bd97 100644 --- a/Classes/Core/Testbase.php +++ b/Classes/Core/Testbase.php @@ -133,16 +133,16 @@ private function findShortestPathCode(string $from, string $to): string } $commonPath = $to; - while (strpos($from . '/', $commonPath . '/') !== 0 && $commonPath !== '/' && preg_match('{^[a-z]:/?$}i', $commonPath) !== false && $commonPath !== '.') { + while (!str_starts_with($from . '/', $commonPath . '/') && $commonPath !== '/' && preg_match('{^[a-z]:/?$}i', $commonPath) !== false && $commonPath !== '.') { $commonPath = str_replace('\\', '/', \dirname($commonPath)); } - if ($commonPath === '/' || $commonPath === '.' || strpos($from, $commonPath) !== 0) { + if ($commonPath === '/' || $commonPath === '.' || !str_starts_with($from, $commonPath)) { return var_export($to, true); } $commonPath = rtrim($commonPath, '/') . '/'; - if (strpos($to, $from . '/') === 0) { + if (str_starts_with($to, $from . '/')) { return '__DIR__ . ' . var_export(substr($to, \strlen($from)), true); } $sourcePathDepth = substr_count(substr($from, \strlen($commonPath)), '/'); @@ -162,7 +162,7 @@ private function findShortestPathCode(string $from, string $to): string public function removeOldInstanceIfExists($instancePath): void { if (is_dir($instancePath)) { - if (strpos($instancePath, 'typo3temp') === false) { + if (!str_contains($instancePath, 'typo3temp')) { // Simple safe guard to not delete something else - test instance must contain at least typo3temp throw new \RuntimeException( 'Test instance to delete must be within typo3temp', @@ -204,7 +204,7 @@ public function setUpInstanceCoreLinks( } foreach ($coreExtensions as $coreExtension) { $packageInfo = $this->composerPackageManager->getPackageInfoWithFallback($coreExtension); - if (! ($packageInfo?->isSystemExtension() ?? false)) { + if (!($packageInfo?->isSystemExtension() ?? false)) { continue; } $linksToSet[$packageInfo->getRealPath() . '/'] = 'typo3/sysext/' . $packageInfo->getExtensionKey(); diff --git a/Classes/Core/Unit/UnitTestCase.php b/Classes/Core/Unit/UnitTestCase.php index 45c740e6..b5804ee4 100644 --- a/Classes/Core/Unit/UnitTestCase.php +++ b/Classes/Core/Unit/UnitTestCase.php @@ -141,8 +141,8 @@ protected function tearDown(): void if (!GeneralUtility::validPathStr($absoluteFileName)) { throw new \RuntimeException('tearDown() cleanup: Filename contains illegal characters', 1410633087); } - if (strpos($absoluteFileName, Environment::getVarPath()) !== 0 - && strpos($absoluteFileName, Environment::getPublicPath() . '/typo3temp/') !== 0 + if (!str_starts_with($absoluteFileName, Environment::getVarPath()) + && !str_starts_with($absoluteFileName, Environment::getPublicPath() . '/typo3temp/') ) { throw new \RuntimeException( 'tearDown() cleanup: Files to delete must be within ' . Environment::getVarPath() . ' or ' . Environment::getPublicPath() . '/typo3temp/', @@ -186,7 +186,7 @@ protected function tearDown(): void self::assertTrue($this->setUpMethodCallChainValid, 'tearDown() integrity check detected that setUp has a ' . 'broken parent call chain. Please check that setUp() methods properly calls parent::setUp(), starting from "' - . get_class($this) . '"'); + . static::class . '"'); parent::tearDown(); } diff --git a/composer.json b/composer.json index 0d374ee7..03592e24 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ } }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.11.0", + "friendsofphp/php-cs-fixer": "^3.37.1", "phpstan/phpstan": "^1.9.2", "phpstan/phpstan-phpunit": "^1.1.1", "typo3/cms-workspaces": "12.*.*@dev || 13.*.*@dev"