Skip to content

Commit

Permalink
Do not infer property types from constructor if the property already …
Browse files Browse the repository at this point in the history
…has a native type
  • Loading branch information
ondrejmirtes committed Dec 15, 2020
1 parent 7537f81 commit d245dab
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 70 deletions.
1 change: 1 addition & 0 deletions src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ private function createProperty(
&& $this->inferPrivatePropertyTypeFromConstructor
&& $declaringClassReflection->getFileName() !== false
&& $propertyReflection->isPrivate()
&& (!method_exists($propertyReflection, 'hasType') || !$propertyReflection->hasType())
&& $declaringClassReflection->hasConstructor()
&& $declaringClassReflection->getConstructor()->getDeclaringClass()->getName() === $declaringClassReflection->getName()
) {
Expand Down
10 changes: 0 additions & 10 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10511,15 +10511,6 @@ public function dataBug2945(): array
return $this->gatherAssertTypes(__DIR__ . '/data/bug-2945.php');
}

public function dataInferPrivateTypedPropertyTypeFromConstructor(): array
{
if (!self::$useStaticReflectionProvider && PHP_VERSION_ID < 70400) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

return $this->gatherAssertTypes(__DIR__ . '/data/infer-private-typed-property-type-from-constructor.php');
}

public function dataBug4207(): array
{
return $this->gatherAssertTypes(__DIR__ . '/data/bug-4207.php');
Expand Down Expand Up @@ -10723,7 +10714,6 @@ private function gatherAssertTypes(string $file): array
* @dataProvider dataBug2997
* @dataProvider dataBug1657
* @dataProvider dataBug2945
* @dataProvider dataInferPrivateTypedPropertyTypeFromConstructor
* @dataProvider dataBug4207
* @dataProvider dataBug4206
* @dataProvider dataBugEmptyArray
Expand Down

This file was deleted.

0 comments on commit d245dab

Please sign in to comment.