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

Fix #4751 - allow MethodSignatureMismatch to be overridable when info comes from docblock

This commit is contained in:
Matt Brown 2020-12-02 15:13:28 -05:00
parent e2bb02e93c
commit db8a3ab846
6 changed files with 37 additions and 2 deletions

View File

@ -252,7 +252,8 @@ class MethodComparator
new MethodSignatureMismatch(
'Method ' . $cased_guide_method_id . ' is declared final and cannot be overridden',
$code_location
)
),
$guide_method_storage->final_from_docblock ? $suppressed_issues : []
)) {
// fall through
}

View File

@ -569,7 +569,10 @@ class ClassLikeNodeScanner
$storage->internal = $docblock_info->psalm_internal ?? '';
}
$storage->final = $storage->final || $docblock_info->final;
if ($docblock_info->final && !$storage->final) {
$storage->final = true;
$storage->final_from_docblock = true;
}
$storage->preserve_constructor_signature = $docblock_info->consistent_constructor;

View File

@ -141,6 +141,7 @@ class FunctionLikeNodeScanner
$storage->defining_fqcln = '';
$storage->is_static = $stmt->isStatic();
$storage->final = $this->classlike_storage && $this->classlike_storage->final;
$storage->final_from_docblock = $this->classlike_storage && $this->classlike_storage->final_from_docblock;
} elseif ($stmt instanceof PhpParser\Node\Stmt\Function_) {
$cased_function_id =
($this->aliases->namespace ? $this->aliases->namespace . '\\' : '') . $stmt->name->name;
@ -293,6 +294,7 @@ class FunctionLikeNodeScanner
$storage->abstract = $stmt->isAbstract();
$storage->final = $classlike_storage->final || $stmt->isFinal();
$storage->final_from_docblock = $classlike_storage->final_from_docblock;
if ($stmt->isPrivate()) {
$storage->visibility = ClassLikeAnalyzer::VISIBILITY_PRIVATE;

View File

@ -166,6 +166,11 @@ class ClassLikeStorage
*/
public $final = false;
/**
* @var bool
*/
public $final_from_docblock = false;
/**
* @var array<lowercase-string, string>
*/

View File

@ -20,6 +20,11 @@ class MethodStorage extends FunctionLikeStorage
*/
public $final = false;
/**
* @var bool
*/
public $final_from_docblock = false;
/**
* @var bool
*/

View File

@ -828,6 +828,25 @@ class MethodSignatureTest extends TestCase
[],
'8.0'
],
'suppressDocblockFinal' => [
'<?php
/**
* @final
*/
class A {
public function foo(): void {}
}
/**
* @psalm-suppress InvalidExtendClass
*/
class B extends A {
/**
* @psalm-suppress MethodSignatureMismatch
*/
public function foo(): void {}
}'
],
];
}