mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #314 - add a way to indicate @method list is comprehensive
This commit is contained in:
parent
1c7568e612
commit
2fabdf3353
@ -305,6 +305,10 @@ class CommentChecker
|
||||
$info->sealed_properties = true;
|
||||
}
|
||||
|
||||
if (isset($comments['specials']['psalm-seal-methods'])) {
|
||||
$info->sealed_methods = true;
|
||||
}
|
||||
|
||||
if (isset($comments['specials']['psalm-suppress'])) {
|
||||
/** @var string $suppress_entry */
|
||||
foreach ($comments['specials']['psalm-suppress'] as $suppress_entry) {
|
||||
|
@ -270,13 +270,13 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
|
||||
$statements_checker->getSource()
|
||||
)
|
||||
) {
|
||||
$has_valid_method_call_type = true;
|
||||
$existent_method_ids[] = $method_id;
|
||||
|
||||
if ($var_id !== '$this') {
|
||||
$class_storage = $project_checker->classlike_storage_provider->get($fq_class_name);
|
||||
|
||||
if (isset($class_storage->pseudo_methods[$method_name_lc])) {
|
||||
$has_valid_method_call_type = true;
|
||||
$existent_method_ids[] = $method_id;
|
||||
|
||||
$pseudo_method_storage = $class_storage->pseudo_methods[$method_name_lc];
|
||||
|
||||
if (self::checkFunctionArguments(
|
||||
@ -316,9 +316,15 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
|
||||
|
||||
continue;
|
||||
}
|
||||
} elseif ($class_storage->sealed_methods) {
|
||||
$non_existent_method_ids[] = $method_id;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$has_valid_method_call_type = true;
|
||||
$existent_method_ids[] = $method_id;
|
||||
|
||||
$return_type = Type::getMixed();
|
||||
continue;
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ class ClassLikeDocblockComment
|
||||
*/
|
||||
public $sealed_properties = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $sealed_methods = false;
|
||||
|
||||
/**
|
||||
* @var array<int, string>
|
||||
*/
|
||||
|
@ -52,6 +52,11 @@ class ClassLikeStorage
|
||||
*/
|
||||
public $sealed_properties = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $sealed_methods = false;
|
||||
|
||||
/**
|
||||
* @var array<int, string>
|
||||
*/
|
||||
|
@ -264,6 +264,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
|
||||
$storage->deprecated = $docblock_info->deprecated;
|
||||
|
||||
$storage->sealed_properties = $docblock_info->sealed_properties;
|
||||
$storage->sealed_methods = $docblock_info->sealed_methods;
|
||||
|
||||
$storage->suppressed_issues = $docblock_info->suppressed_issues;
|
||||
|
||||
|
@ -1680,6 +1680,23 @@ class AnnotationTest extends TestCase
|
||||
class Child extends Parent {}',
|
||||
'error_message' => 'InvalidDocblock',
|
||||
],
|
||||
'magicMethodAnnotationWithSealed' => [
|
||||
'<?php
|
||||
class Parent {
|
||||
public function __call() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method string getString()
|
||||
* @psalm-seal-methods
|
||||
*/
|
||||
class Child extends Parent {}
|
||||
|
||||
$child = new Child();
|
||||
$child->getString();
|
||||
$child->foo();',
|
||||
'error_message' => 'UndefinedMethod - src/somefile.php:14 - Method Child::foo does not exist',
|
||||
],
|
||||
'magicMethodAnnotationInvalidArg' => [
|
||||
'<?php
|
||||
class Parent {
|
||||
|
Loading…
Reference in New Issue
Block a user