Skip to content

Commit 3a57521

Browse files
committed
Do not inherit constructor PHPDocs from internal classes
1 parent fb55535 commit 3a57521

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

src/PhpDoc/PhpDocInheritanceResolver.php

+7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ private function docBlockTreeToResolvedDocBlock(PhpDocBlock $phpDocBlock, ?strin
7777
$parentPhpDocBlocks = [];
7878

7979
foreach ($phpDocBlock->getParents() as $parentPhpDocBlock) {
80+
if (
81+
$parentPhpDocBlock->getClassReflection()->isBuiltin()
82+
&& $functionName !== null
83+
&& strtolower($functionName) === '__construct'
84+
) {
85+
continue;
86+
}
8087
$parents[] = $this->docBlockTreeToResolvedDocBlock(
8188
$parentPhpDocBlock,
8289
$parentPhpDocBlock->getTrait(),

tests/PHPStan/Rules/Classes/InstantiationRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,9 @@ public function testOldStyleConstructorOnPhp7(): void
264264
$this->analyse([__DIR__ . '/data/php80-constructor.php'], $errors);
265265
}
266266

267+
public function testBug4030(): void
268+
{
269+
$this->analyse([__DIR__ . '/data/bug-4030.php'], []);
270+
}
271+
267272
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Bug4011;
4+
5+
class Foo extends \FilterIterator
6+
{
7+
public function __construct(\Traversable $iterator)
8+
{
9+
10+
}
11+
12+
public function accept()
13+
{
14+
return true;
15+
}
16+
}
17+
18+
function (\Traversable $t) {
19+
new Foo($t);
20+
};

tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ public function testTraitCrash(): void
3535
$this->analyse([__DIR__ . '/data/incompatible-default-parameter-type-trait-crash.php'], []);
3636
}
3737

38+
public function testBug4011(): void
39+
{
40+
$this->analyse([__DIR__ . '/data/bug-4011.php'], []);
41+
}
42+
3843
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Bug4011;
4+
5+
class ParseException extends \Exception
6+
{
7+
public function __construct(string $message = '', $code = '')
8+
{
9+
10+
}
11+
}

0 commit comments

Comments
 (0)