diff --git a/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php index 8325cd759da..5a73e39c030 100644 --- a/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php +++ b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php @@ -139,6 +139,22 @@ private function fixFunctionParameters(Tokens $tokens, array $arguments) } $argumentTypeInfo = $argumentInfo->getTypeAnalysis(); + + if ( + \PHP_VERSION_ID >= 80000 + && false === $this->configuration['use_nullable_type_declaration'] + ) { + $visibility = $tokens[$tokens->getPrevMeaningfulToken($argumentTypeInfo->getStartIndex())]; + + if ($visibility->isGivenKind([ + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, + ])) { + continue; + } + } + if (true === $this->configuration['use_nullable_type_declaration']) { if (!$argumentTypeInfo->isNullable() && 'mixed' !== $argumentTypeInfo->getName()) { $tokens->insertAt($argumentTypeInfo->getStartIndex(), new Token([CT::T_NULLABLE_TYPE, '?'])); diff --git a/tests/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixerTest.php b/tests/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixerTest.php index 7ff546cc429..b6d9c879f6c 100644 --- a/tests/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixerTest.php +++ b/tests/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixerTest.php @@ -406,25 +406,52 @@ public function provideFixPhp74Cases() } /** - * @param string $expected + * @param null|string $expected + * @param string $input + * + * @dataProvider provideFix80Cases + * @requires PHP 8.0 + */ + public function testFix80($input, $expected = null) + { + if (null === $expected) { + $this->doTest($input); + } else { + $this->doTest($expected, $input); + } + } + + /** * @param null|string $input + * @param string $expected * * @dataProvider provideFix80Cases * @requires PHP 8.0 */ - public function testFix80($expected, $input = null) + public function testFixInverse80($expected, $input = null) { + $this->fixer->configure(['use_nullable_type_declaration' => false]); + $this->doTest($expected, $input); } public function provideFix80Cases() { yield 'trailing comma' => [ - ' [ + '