Skip to content

Commit 753fc4d

Browse files
committed
Fix resolving tentative return type
1 parent 2da94f8 commit 753fc4d

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/Reflection/Native/NativeMethodReflection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getPrototype(): ClassMemberReflection
8181

8282
$tentativeReturnType = null;
8383
if ($prototypeMethod->getTentativeReturnType() !== null) {
84-
$tentativeReturnType = TypehintHelper::decideTypeFromReflection($prototypeMethod->getTentativeReturnType());
84+
$tentativeReturnType = TypehintHelper::decideTypeFromReflection($prototypeMethod->getTentativeReturnType(), null, $prototypeDeclaringClass);
8585
}
8686

8787
return new MethodPrototypeReflection(

src/Reflection/Php/PhpMethodReflection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function getPrototype(): ClassMemberReflection
118118

119119
$tentativeReturnType = null;
120120
if ($prototypeMethod->getTentativeReturnType() !== null) {
121-
$tentativeReturnType = TypehintHelper::decideTypeFromReflection($prototypeMethod->getTentativeReturnType());
121+
$tentativeReturnType = TypehintHelper::decideTypeFromReflection($prototypeMethod->getTentativeReturnType(), null, $prototypeDeclaringClass);
122122
}
123123

124124
return new MethodPrototypeReflection(

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -812,4 +812,10 @@ public function testBug9524(): void
812812
$this->analyse([__DIR__ . '/data/bug-9524.php'], []);
813813
}
814814

815+
public function testSimpleXmlElementChildClass(): void
816+
{
817+
$this->phpVersionId = PHP_VERSION_ID;
818+
$this->analyse([__DIR__ . '/data/simple-xml-element-child.php'], []);
819+
}
820+
815821
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace SimpleXmlElementChild;
4+
5+
class CustomXMLElement extends \SimpleXMLElement
6+
{
7+
#[\Override]
8+
public function addChild(string $qualifiedName, ?string $value = null, ?string $namespace = null): ?static
9+
{
10+
return parent::addChild($qualifiedName, $this->escapeInput($value), $namespace);
11+
}
12+
13+
private function escapeInput(?string $value): ?string
14+
{
15+
if ($value === null) {
16+
return null;
17+
}
18+
return htmlspecialchars((string) normalizer_normalize($value), ENT_XML1, 'UTF-8');
19+
}
20+
}

0 commit comments

Comments
 (0)