diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/keep_string_type_simple.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/keep_string_type_simple.php.inc new file mode 100644 index 00000000000..934ba63e8ec --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture/keep_string_type_simple.php.inc @@ -0,0 +1,54 @@ + +----- +> + */ + public static function provideData(): \Iterator + { + $anotherTypeObjectType = new ObjectType(AnotherType::class); + yield [__DIR__ . '/Fixture/new_class.php.inc', 1, $anotherTypeObjectType]; + yield [__DIR__ . '/Fixture/argument_typehint.php.inc', 1, $anotherTypeObjectType]; + } +} + +?> diff --git a/rules/Privatization/TypeManipulator/TypeNormalizer.php b/rules/Privatization/TypeManipulator/TypeNormalizer.php index af3bbe8e7e6..e29c0c16df5 100644 --- a/rules/Privatization/TypeManipulator/TypeNormalizer.php +++ b/rules/Privatization/TypeManipulator/TypeNormalizer.php @@ -4,6 +4,8 @@ namespace Rector\Privatization\TypeManipulator; +use PHPStan\Type\Accessory\AccessoryLiteralStringType; +use PHPStan\Type\Accessory\AccessoryNonFalsyStringType; use PHPStan\Type\ArrayType; use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantArrayType; @@ -55,6 +57,10 @@ public function generalizeConstantBoolTypes(Type $type): Type public function generalizeConstantTypes(Type $type): Type { return TypeTraverser::map($type, function (Type $type, callable $traverseCallback): Type { + if ($type instanceof AccessoryNonFalsyStringType || $type instanceof AccessoryLiteralStringType) { + return new StringType(); + } + if ($type instanceof ConstantBooleanType) { return new BooleanType(); }