diff --git a/doc/list.rst b/doc/list.rst index 3e7aea96d98..2ccc6e197a3 100644 --- a/doc/list.rst +++ b/doc/list.rst @@ -2603,7 +2603,7 @@ List of Available Rules `Source PhpCsFixer\\Fixer\\ReturnNotation\\ReturnAssignmentFixer <./../src/Fixer/ReturnNotation/ReturnAssignmentFixer.php>`_ - `return_type_declaration <./rules/function_notation/return_type_declaration.rst>`_ - There should be one or no space before colon, and one space after it in return type declarations, according to configuration. + Adjust spacing around colon in return type declarations and backed enum types. Rule is applied only in a PHP 7+ environment. diff --git a/doc/rules/function_notation/return_type_declaration.rst b/doc/rules/function_notation/return_type_declaration.rst index edad00af62a..371b3c3a922 100644 --- a/doc/rules/function_notation/return_type_declaration.rst +++ b/doc/rules/function_notation/return_type_declaration.rst @@ -2,8 +2,7 @@ Rule ``return_type_declaration`` ================================ -There should be one or no space before colon, and one space after it in return -type declarations, according to configuration. +Adjust spacing around colon in return type declarations and backed enum types. Description ----------- diff --git a/doc/rules/index.rst b/doc/rules/index.rst index d644bba4bfc..127d0725c67 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -375,7 +375,7 @@ Function Notation Callables must be called without using ``call_user_func*`` when possible. - `return_type_declaration <./function_notation/return_type_declaration.rst>`_ - There should be one or no space before colon, and one space after it in return type declarations, according to configuration. + Adjust spacing around colon in return type declarations and backed enum types. - `single_line_throw <./function_notation/single_line_throw.rst>`_ Throwing exception must be done in single line. diff --git a/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php b/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php index fe3015929f0..eea0fb89da3 100644 --- a/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php +++ b/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php @@ -37,7 +37,7 @@ final class ReturnTypeDeclarationFixer extends AbstractFixer implements Configur public function getDefinition(): FixerDefinitionInterface { return new FixerDefinition( - 'There should be one or no space before colon, and one space after it in return type declarations, according to configuration.', + 'Adjust spacing around colon in return type declarations and backed enum types.', [ new CodeSample( "doTest($expected, $input); + } + + public function provideFix81Cases(): iterable + { + yield [ + ' [];', ]; } + + /** + * @dataProvider provideEnumTypeColonCases + * @requires PHP 8.1 + */ + public function testEnumTypeColon(string $expected, string $input): void + { + $this->fixer->configure([ + 'constructs' => [ + 'type_colon', + ], + ]); + + $this->doTest($expected, $input); + } + + public function provideEnumTypeColonCases(): iterable + { + yield [ + '