From f35e0621aa9f200a3ca05a0a1cc030560634f315 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 12 Jul 2026 12:37:35 +0200 Subject: [PATCH 1/3] [StaticTypeMapper] Map literal-string docblock type to AccessoryLiteralStringType --- .../Fixture/skip_literal_string_narrowing.php.inc | 14 ++++++++++++++ .../Mapper/ScalarStringToTypeMapper.php | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_literal_string_narrowing.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_literal_string_narrowing.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_literal_string_narrowing.php.inc new file mode 100644 index 00000000000..8b6fdb241ac --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_literal_string_narrowing.php.inc @@ -0,0 +1,14 @@ + ['string'], AccessoryNonEmptyStringType::class => ['non-empty-string'], + AccessoryLiteralStringType::class => ['literal-string'], NonEmptyArrayType::class => ['non-empty-array'], ClassStringType::class => ['class-string'], FloatType::class => ['float', 'real', 'double'], From 20e9a16e050212714da3dcedd5f30a2767cadb62 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 12 Jul 2026 12:38:20 +0200 Subject: [PATCH 2/3] add non-empty-string regression fixture --- .../skip_non_empty_string_narrowing.php.inc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_non_empty_string_narrowing.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_non_empty_string_narrowing.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_non_empty_string_narrowing.php.inc new file mode 100644 index 00000000000..78f81f6c735 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_non_empty_string_narrowing.php.inc @@ -0,0 +1,14 @@ + Date: Sun, 12 Jul 2026 12:41:52 +0200 Subject: [PATCH 3/3] map more phpstan-special types: numeric/non-falsy/lowercase/uppercase-string, non-negative/non-positive-int, array-key --- .../skip_lowercase_string_narrowing.php.inc | 14 +++++++++++++ .../skip_non_falsy_string_narrowing.php.inc | 14 +++++++++++++ .../skip_non_negative_int_narrowing.php.inc | 14 +++++++++++++ .../skip_non_positive_int_narrowing.php.inc | 14 +++++++++++++ .../skip_numeric_string_narrowing.php.inc | 14 +++++++++++++ .../skip_uppercase_string_narrowing.php.inc | 14 +++++++++++++ .../Mapper/ScalarStringToTypeMapper.php | 21 +++++++++++++++++++ 7 files changed, 105 insertions(+) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_lowercase_string_narrowing.php.inc create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_non_falsy_string_narrowing.php.inc create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_non_negative_int_narrowing.php.inc create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_non_positive_int_narrowing.php.inc create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_numeric_string_narrowing.php.inc create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_uppercase_string_narrowing.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_lowercase_string_narrowing.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_lowercase_string_narrowing.php.inc new file mode 100644 index 00000000000..c7a75ca989f --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveReturnTagIncompatibleWithNativeTypeRector/Fixture/skip_lowercase_string_narrowing.php.inc @@ -0,0 +1,14 @@ + ['string'], AccessoryNonEmptyStringType::class => ['non-empty-string'], AccessoryLiteralStringType::class => ['literal-string'], + AccessoryNumericStringType::class => ['numeric-string'], + AccessoryNonFalsyStringType::class => ['non-falsy-string', 'truthy-string'], + AccessoryLowercaseStringType::class => ['lowercase-string'], + AccessoryUppercaseStringType::class => ['uppercase-string'], NonEmptyArrayType::class => ['non-empty-array'], ClassStringType::class => ['class-string'], FloatType::class => ['float', 'real', 'double'], @@ -70,6 +79,18 @@ public function mapScalarStringToType(string $scalarName): Type return IntegerRangeType::createAllSmallerThan(0); } + if ($loweredScalarName === 'non-negative-int') { + return IntegerRangeType::fromInterval(0, null); + } + + if ($loweredScalarName === 'non-positive-int') { + return IntegerRangeType::fromInterval(null, 0); + } + + if ($loweredScalarName === 'array-key') { + return new UnionType([new IntegerType(), new StringType()]); + } + foreach (self::SCALAR_NAME_BY_TYPE as $objectType => $scalarNames) { if (! in_array($loweredScalarName, $scalarNames, true)) { continue;