1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Enforce immutability constraints only on interface methods

This commit is contained in:
Matthew Brown 2019-09-22 09:26:26 -04:00
parent 3d84518eab
commit add051c2be
2 changed files with 16 additions and 15 deletions

View File

@ -516,21 +516,6 @@ class ClassAnalyzer extends ClassLikeAnalyzer
}
}
if ($interface_storage->external_mutation_free
&& !$storage->external_mutation_free
) {
if (IssueBuffer::accepts(
new MissingImmutableAnnotation(
$interface_name . ' is marked immutable, but '
. $fq_class_name . ' is not marked immutable',
$code_location
),
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
// fall through
}
}
foreach ($interface_storage->methods as $method_name => $interface_method_storage) {
if ($interface_method_storage->visibility === self::VISIBILITY_PUBLIC) {
$implementer_declaring_method_id = $codebase->methods->getDeclaringMethodId(

View File

@ -29,6 +29,7 @@ use function strtolower;
use function explode;
use function is_string;
use function in_array;
use Psalm\Issue\MissingImmutableAnnotation;
/**
* @internal
@ -610,6 +611,21 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
}
}
if ($guide_method_storage->external_mutation_free
&& !$implementer_method_storage->external_mutation_free
) {
if (IssueBuffer::accepts(
new MissingImmutableAnnotation(
$cased_guide_method_id . ' is marked immutable, but '
. $implementer_method_id . ' is not marked immutable',
$code_location
),
$suppressed_issues
)) {
// fall through
}
}
if ($guide_method_storage->return_type
&& $implementer_method_storage->return_type
&& ($guide_method_storage->signature_return_type !== $guide_method_storage->return_type