diff --git a/config.xsd b/config.xsd index 0f21145cc..05e12b323 100644 --- a/config.xsd +++ b/config.xsd @@ -275,6 +275,7 @@ + diff --git a/docs/running_psalm/issues/MismatchingDocblockPropertyType.md b/docs/running_psalm/issues/MismatchingDocblockPropertyType.md new file mode 100644 index 000000000..b9b82ba79 --- /dev/null +++ b/docs/running_psalm/issues/MismatchingDocblockPropertyType.md @@ -0,0 +1,11 @@ +# MismatchingDocblockPropertyType + +Emitted when an `@var` entry in a property’s docblock does not match the property's type. + +```php +signature_type) { + $union_comparison_result = new \Psalm\Internal\Type\Comparator\TypeComparisonResult(); + + if (!UnionTypeComparator::isContainedBy( + $codebase, + $fleshed_out_type, + $property_storage->signature_type, + false, + false, + $union_comparison_result + ) && !$union_comparison_result->type_coerced_from_mixed + ) { + if (IssueBuffer::accepts( + new MismatchingDocblockPropertyType( + 'Parameter ' + . $property_class_name . '::$' . $property_name + . ' has wrong type \'' . $fleshed_out_type . + '\', should be \'' . $property_storage->signature_type . '\'', + $property_type_location + ) + )) { + // do nothing + } + } + } } if ($property_storage->is_static) { diff --git a/src/Psalm/Issue/MismatchingDocblockPropertyType.php b/src/Psalm/Issue/MismatchingDocblockPropertyType.php new file mode 100644 index 000000000..6955bfd27 --- /dev/null +++ b/src/Psalm/Issue/MismatchingDocblockPropertyType.php @@ -0,0 +1,8 @@ +foo;', 'error_message' => 'InaccessibleProperty', ], + 'overwritePropertyType' => [ + ' 'MismatchingDocblockPropertyType', + ], ]; } }