File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -346,11 +346,18 @@ private static function resolvePhpDocBlockFromClass(
346346 }
347347 $ methodVariants = $ parentReflection ->getVariants ();
348348 $ positionalMethodParameterNames = [];
349- if (count ($ methodVariants ) === 1 ) {
349+ $ lowercaseMethodName = strtolower ($ parentReflection ->getName ());
350+ if (
351+ count ($ methodVariants ) === 1
352+ && $ lowercaseMethodName !== '__construct '
353+ && $ lowercaseMethodName !== strtolower ($ parentReflection ->getDeclaringClass ()->getName ())
354+ ) {
350355 $ methodParameters = $ methodVariants [0 ]->getParameters ();
351356 foreach ($ methodParameters as $ methodParameter ) {
352357 $ positionalMethodParameterNames [] = $ methodParameter ->getName ();
353358 }
359+ } else {
360+ $ positionalMethodParameterNames = $ positionalParameterNames ;
354361 }
355362 } else {
356363 $ traitReflection = null ;
Original file line number Diff line number Diff line change @@ -9742,6 +9742,11 @@ public function dataPhpDocInheritanceParameterRemapping(): array
97429742 return $ this ->gatherAssertTypes (__DIR__ . '/data/inheritdoc-parameter-remapping.php ' );
97439743 }
97449744
9745+ public function dataPhpDocInheritanceConstructors (): array
9746+ {
9747+ return $ this ->gatherAssertTypes (__DIR__ . '/data/inheritdoc-constructors.php ' );
9748+ }
9749+
97459750 public function dataListType (): array
97469751 {
97479752 return $ this ->gatherAssertTypes (__DIR__ . '/data/list-type.php ' );
@@ -9767,6 +9772,7 @@ public function dataListType(): array
97679772 * @dataProvider dataBug2648
97689773 * @dataProvider dataBug2740
97699774 * @dataProvider dataPhpDocInheritanceParameterRemapping
9775+ * @dataProvider dataPhpDocInheritanceConstructors
97709776 * @dataProvider dataListType
97719777 * @dataProvider dataBug2822
97729778 * @param ConstantStringType $expectedType
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace InheritDocConstructors ;
4+
5+ use function PHPStan \Analyser \assertType ;
6+
7+ class Foo
8+ {
9+
10+ /**
11+ * @param string[] $data
12+ */
13+ public function __construct ($ data )
14+ {
15+ assertType ('array<string> ' , $ data );
16+ }
17+
18+ }
19+
20+ class Bar extends Foo
21+ {
22+
23+ public function __construct ($ name , $ data )
24+ {
25+ parent ::__construct ($ data );
26+ assertType ('mixed ' , $ name );
27+ assertType ('array<string> ' , $ data );
28+ }
29+
30+ }
You can’t perform that action at this time.
0 commit comments