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 12a2b0c5..855f7573 100644 --- a/Classes/Composer/ComposerPackageManager.php +++ b/Classes/Composer/ComposerPackageManager.php @@ -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 $t) { + } catch (\Throwable $t) { // 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/ExtensionTestEnvironment.php b/Classes/Composer/ExtensionTestEnvironment.php index d2a4229c..57bc0dcd 100644 --- a/Classes/Composer/ExtensionTestEnvironment.php +++ b/Classes/Composer/ExtensionTestEnvironment.php @@ -1,6 +1,7 @@ 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 e1747718..c3979979 100644 --- a/Classes/Core/Acceptance/Extension/BackendEnvironment.php +++ b/Classes/Core/Acceptance/Extension/BackendEnvironment.php @@ -30,6 +30,4 @@ class_alias(BackendEnvironmentCodeceptionFive::class, 'TYPO3\\TestingFramework\\ class_alias(BackendEnvironmentCodeceptionFour::class, 'TYPO3\\TestingFramework\\Core\\Acceptance\\Extension\\BackendEnvironmentCoreConditionalParent'); } -abstract class BackendEnvironment extends BackendEnvironmentCoreConditionalParent -{ -} +abstract class BackendEnvironment extends BackendEnvironmentCoreConditionalParent {} diff --git a/Classes/Core/Acceptance/Helper/AbstractModalDialog.php b/Classes/Core/Acceptance/Helper/AbstractModalDialog.php index 3e12fa15..df227c43 100644 --- a/Classes/Core/Acceptance/Helper/AbstractModalDialog.php +++ b/Classes/Core/Acceptance/Helper/AbstractModalDialog.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]) @@ -130,7 +130,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/DataHandling/ActionService.php b/Classes/Core/Functional/Framework/DataHandling/ActionService.php index dc541b61..60f0def8 100644 --- a/Classes/Core/Functional/Framework/DataHandling/ActionService.php +++ b/Classes/Core/Functional/Framework/DataHandling/ActionService.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']); @@ -494,7 +495,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); @@ -513,7 +514,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/CsvWriterStreamFilter.php b/Classes/Core/Functional/Framework/DataHandling/CsvWriterStreamFilter.php index f99fc9e2..5e4877ba 100644 --- a/Classes/Core/Functional/Framework/DataHandling/CsvWriterStreamFilter.php +++ b/Classes/Core/Functional/Framework/DataHandling/CsvWriterStreamFilter.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 @@ get_class($this)] + ['__type' => static::class] ); } diff --git a/Classes/Core/Functional/Framework/Frontend/InternalRequest.php b/Classes/Core/Functional/Framework/Frontend/InternalRequest.php index e92bd083..d3b81e19 100644 --- a/Classes/Core/Functional/Framework/Frontend/InternalRequest.php +++ b/Classes/Core/Functional/Framework/Frontend/InternalRequest.php @@ -215,7 +215,7 @@ public function getInstruction(string $identifier): ?AbstractInstruction return $this->instructions[$identifier] ?? null; } - public function withParsedBody(?array $parsedBody=null): InternalRequest + public function withParsedBody(?array $parsedBody = null): InternalRequest { $target = clone $this; $target->parsedBody = $parsedBody; diff --git a/Classes/Core/Functional/Framework/Frontend/Response.php b/Classes/Core/Functional/Framework/Frontend/Response.php index e742668a..e963c087 100644 --- a/Classes/Core/Functional/Framework/Frontend/Response.php +++ b/Classes/Core/Functional/Framework/Frontend/Response.php @@ -22,7 +22,7 @@ */ class Response { - const STATUS_Failure = 'failure'; + public const STATUS_Failure = 'failure'; /** * @var string diff --git a/Classes/Core/Functional/FunctionalTestCase.php b/Classes/Core/Functional/FunctionalTestCase.php index c9e31804..fc35fbbb 100644 --- a/Classes/Core/Functional/FunctionalTestCase.php +++ b/Classes/Core/Functional/FunctionalTestCase.php @@ -289,7 +289,7 @@ protected function setUp(): void $testbase->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 { @@ -931,7 +931,7 @@ protected function renderRecords(array $assertion, array $record): string foreach ($columns as $columnIndex => $column) { $columnLength = null; foreach ($column as $value) { - if (strpos((string)$value, ' $value) { - if (strpos((string)$value, ' $value) { - if (strpos((string)$value, '\\*') === 0) { + if (str_starts_with((string)$value, '\\*')) { continue; } @@ -983,7 +983,7 @@ protected function getDifferentFields(array $assertion, array $record): array throw new \ValueError(sprintf('"%s" column not found in the input data.', $field)); } - if (strpos((string)$value, 'getPackagesPath() . '/' . str_replace('PACKAGE:', '', $path); } return $path; diff --git a/Classes/Core/Unit/UnitTestCase.php b/Classes/Core/Unit/UnitTestCase.php index 42c23b1e..fb979795 100644 --- a/Classes/Core/Unit/UnitTestCase.php +++ b/Classes/Core/Unit/UnitTestCase.php @@ -134,7 +134,7 @@ protected function tearDown(): void && !$property->isStatic() && $declaringClass !== UnitTestCase::class && $declaringClass !== BaseTestCase::class - && strpos($property->getDeclaringClass()->getName(), 'PHPUnit') !== 0 + && !str_starts_with($property->getDeclaringClass()->getName(), 'PHPUnit') ) { $propertyName = $property->getName(); unset($this->$propertyName); @@ -148,8 +148,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/', diff --git a/Resources/Core/Build/Scripts/splitAcceptanceTests.php b/Resources/Core/Build/Scripts/splitAcceptanceTests.php index 5c176955..1716754a 100755 --- a/Resources/Core/Build/Scripts/splitAcceptanceTests.php +++ b/Resources/Core/Build/Scripts/splitAcceptanceTests.php @@ -223,7 +223,7 @@ public function enterNode(Node $node): void ); foreach ($matches['annotations'] as $possibleDataProvider) { // See if this test has a data provider attached - if (strpos($possibleDataProvider, 'dataProvider') === 0) { + if (str_starts_with($possibleDataProvider, 'dataProvider')) { $test['dataProvider'] = trim(ltrim($possibleDataProvider, 'dataProvider')); } } diff --git a/Resources/Core/Build/Scripts/splitFunctionalTests.php b/Resources/Core/Build/Scripts/splitFunctionalTests.php index a83bd433..858d2847 100755 --- a/Resources/Core/Build/Scripts/splitFunctionalTests.php +++ b/Resources/Core/Build/Scripts/splitFunctionalTests.php @@ -278,7 +278,7 @@ public function enterNode(Node $node): void ]; foreach ($matches['annotations'] as $possibleDataProvider) { // See if this test has a data provider attached - if (strpos($possibleDataProvider, 'dataProvider') === 0) { + if (str_starts_with($possibleDataProvider, 'dataProvider')) { $test['dataProvider'] = trim(ltrim($possibleDataProvider, 'dataProvider')); } } diff --git a/composer.json b/composer.json index c763c0dc..88896d05 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,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": "11.*.*@dev"