1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Don’t complain about untyped properties missing constructors

This commit is contained in:
Brown 2019-08-13 13:38:15 -04:00
parent b5614d03f8
commit 3ff2a64e16

View File

@ -1036,6 +1036,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$uninitialized_variables = [];
$uninitialized_properties = [];
$uninitialized_typed_properties = [];
foreach ($storage->appearing_property_ids as $property_name => $appearing_property_id) {
$property_class_name = (string) $codebase->properties->getDeclaringClassForProperty(
@ -1083,6 +1084,10 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$uninitialized_variables[] = '$this->' . $property_name;
$uninitialized_properties[$property_class_name . '::$' . $property_name] = $property;
if ($property->type && !$property->type->isMixed()) {
$uninitialized_typed_properties[$property_class_name . '::$' . $property_name] = $property;
}
}
if (!$uninitialized_properties) {
@ -1194,7 +1199,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$constructor_analyzer->analyze($method_context, $global_context, true);
foreach ($uninitialized_properties as $property_id => $property_storage) {
foreach ($uninitialized_typed_properties as $property_id => $property_storage) {
list(,$property_name) = explode('::$', $property_id);
if (!isset($method_context->vars_in_scope['$this->' . $property_name])) {
@ -1256,8 +1261,8 @@ class ClassAnalyzer extends ClassLikeAnalyzer
return;
}
if (!$storage->abstract) {
$first_uninitialized_property = array_shift($uninitialized_properties);
if (!$storage->abstract && $uninitialized_typed_properties) {
$first_uninitialized_property = array_shift($uninitialized_typed_properties);
if ($first_uninitialized_property->location) {
if (IssueBuffer::accepts(