From 6696f4597bdc788faf5c26dc223340290de2e890 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 16 Jun 2022 15:21:43 +0200 Subject: [PATCH] allow numeric-strings beeing returned for non-empty-string --- .../Accessory/AccessoryNumericStringType.php | 4 +++ .../Rules/Methods/ReturnTypeRuleTest.php | 5 ++++ tests/PHPStan/Rules/Methods/data/bug-7265.php | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/PHPStan/Rules/Methods/data/bug-7265.php diff --git a/src/Type/Accessory/AccessoryNumericStringType.php b/src/Type/Accessory/AccessoryNumericStringType.php index 2e720c9800..fbc1bc4ce3 100644 --- a/src/Type/Accessory/AccessoryNumericStringType.php +++ b/src/Type/Accessory/AccessoryNumericStringType.php @@ -78,6 +78,10 @@ public function isSubTypeOf(Type $otherType): TrinaryLogic public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic { + if ($acceptingType->isNonEmptyString()->yes()) { + return TrinaryLogic::createYes(); + } + return $this->isSubTypeOf($acceptingType); } diff --git a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php index eec5f3ae9c..d780032ebd 100644 --- a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php @@ -695,4 +695,9 @@ public function testConditionalTypes(): void ]); } + public function testBug7265(): void + { + $this->analyse([__DIR__ . '/data/bug-7265.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-7265.php b/tests/PHPStan/Rules/Methods/data/bug-7265.php new file mode 100644 index 0000000000..06012e6349 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-7265.php @@ -0,0 +1,25 @@ +