Skip to content

Commit d245dab

Browse files
committed
Do not infer property types from constructor if the property already has a native type
1 parent 7537f81 commit d245dab

File tree

3 files changed

+1
-70
lines changed

3 files changed

+1
-70
lines changed

src/Reflection/Php/PhpClassReflectionExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ private function createProperty(
303303
&& $this->inferPrivatePropertyTypeFromConstructor
304304
&& $declaringClassReflection->getFileName() !== false
305305
&& $propertyReflection->isPrivate()
306+
&& (!method_exists($propertyReflection, 'hasType') || !$propertyReflection->hasType())
306307
&& $declaringClassReflection->hasConstructor()
307308
&& $declaringClassReflection->getConstructor()->getDeclaringClass()->getName() === $declaringClassReflection->getName()
308309
) {

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10511,15 +10511,6 @@ public function dataBug2945(): array
1051110511
return $this->gatherAssertTypes(__DIR__ . '/data/bug-2945.php');
1051210512
}
1051310513

10514-
public function dataInferPrivateTypedPropertyTypeFromConstructor(): array
10515-
{
10516-
if (!self::$useStaticReflectionProvider && PHP_VERSION_ID < 70400) {
10517-
$this->markTestSkipped('Test requires PHP 7.4.');
10518-
}
10519-
10520-
return $this->gatherAssertTypes(__DIR__ . '/data/infer-private-typed-property-type-from-constructor.php');
10521-
}
10522-
1052310514
public function dataBug4207(): array
1052410515
{
1052510516
return $this->gatherAssertTypes(__DIR__ . '/data/bug-4207.php');
@@ -10723,7 +10714,6 @@ private function gatherAssertTypes(string $file): array
1072310714
* @dataProvider dataBug2997
1072410715
* @dataProvider dataBug1657
1072510716
* @dataProvider dataBug2945
10726-
* @dataProvider dataInferPrivateTypedPropertyTypeFromConstructor
1072710717
* @dataProvider dataBug4207
1072810718
* @dataProvider dataBug4206
1072910719
* @dataProvider dataBugEmptyArray

tests/PHPStan/Analyser/data/infer-private-typed-property-type-from-constructor.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)