diff --git a/src/PhpDoc/PhpDocBlock.php b/src/PhpDoc/PhpDocBlock.php index 0a122346bc..7c38349a8a 100644 --- a/src/PhpDoc/PhpDocBlock.php +++ b/src/PhpDoc/PhpDocBlock.php @@ -346,11 +346,18 @@ private static function resolvePhpDocBlockFromClass( } $methodVariants = $parentReflection->getVariants(); $positionalMethodParameterNames = []; - if (count($methodVariants) === 1) { + $lowercaseMethodName = strtolower($parentReflection->getName()); + if ( + count($methodVariants) === 1 + && $lowercaseMethodName !== '__construct' + && $lowercaseMethodName !== strtolower($parentReflection->getDeclaringClass()->getName()) + ) { $methodParameters = $methodVariants[0]->getParameters(); foreach ($methodParameters as $methodParameter) { $positionalMethodParameterNames[] = $methodParameter->getName(); } + } else { + $positionalMethodParameterNames = $positionalParameterNames; } } else { $traitReflection = null; diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 2e6c944002..9df4bfb0b5 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -9742,6 +9742,11 @@ public function dataPhpDocInheritanceParameterRemapping(): array return $this->gatherAssertTypes(__DIR__ . '/data/inheritdoc-parameter-remapping.php'); } + public function dataPhpDocInheritanceConstructors(): array + { + return $this->gatherAssertTypes(__DIR__ . '/data/inheritdoc-constructors.php'); + } + public function dataListType(): array { return $this->gatherAssertTypes(__DIR__ . '/data/list-type.php'); @@ -9767,6 +9772,7 @@ public function dataListType(): array * @dataProvider dataBug2648 * @dataProvider dataBug2740 * @dataProvider dataPhpDocInheritanceParameterRemapping + * @dataProvider dataPhpDocInheritanceConstructors * @dataProvider dataListType * @dataProvider dataBug2822 * @param ConstantStringType $expectedType diff --git a/tests/PHPStan/Analyser/data/inheritdoc-constructors.php b/tests/PHPStan/Analyser/data/inheritdoc-constructors.php new file mode 100644 index 0000000000..bd5242c799 --- /dev/null +++ b/tests/PHPStan/Analyser/data/inheritdoc-constructors.php @@ -0,0 +1,30 @@ +', $data); + } + +} + +class Bar extends Foo +{ + + public function __construct($name, $data) + { + parent::__construct($data); + assertType('mixed', $name); + assertType('array', $data); + } + +}