mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Seal properties and methods whenever @method/@property is used
This commit is contained in:
parent
bf310fb326
commit
df33405635
@ -1196,6 +1196,9 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
|||||||
$this->implementTemplatedType($storage, $node, $implemented_class_name);
|
$this->implementTemplatedType($storage, $node, $implemented_class_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$storage->sealed_properties = $docblock_info->sealed_properties;
|
||||||
|
$storage->sealed_methods = $docblock_info->sealed_methods;
|
||||||
|
|
||||||
if ($docblock_info->properties) {
|
if ($docblock_info->properties) {
|
||||||
foreach ($docblock_info->properties as $property) {
|
foreach ($docblock_info->properties as $property) {
|
||||||
$pseudo_property_type_tokens = Type::fixUpLocalType(
|
$pseudo_property_type_tokens = Type::fixUpLocalType(
|
||||||
@ -1233,15 +1236,27 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
|||||||
$storage->has_docblock_issues = true;
|
$storage->has_docblock_issues = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$storage->sealed_properties = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($docblock_info->methods as $method) {
|
||||||
|
/** @var MethodStorage */
|
||||||
|
$pseudo_method_storage = $this->registerFunctionLike($method, true);
|
||||||
|
|
||||||
|
if ($pseudo_method_storage->is_static) {
|
||||||
|
$storage->pseudo_static_methods[strtolower($method->name->name)] = $pseudo_method_storage;
|
||||||
|
} else {
|
||||||
|
$storage->pseudo_methods[strtolower($method->name->name)] = $pseudo_method_storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
$storage->sealed_methods = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$storage->deprecated = $docblock_info->deprecated;
|
$storage->deprecated = $docblock_info->deprecated;
|
||||||
$storage->internal = $docblock_info->internal;
|
$storage->internal = $docblock_info->internal;
|
||||||
$storage->psalm_internal = $docblock_info->psalm_internal;
|
$storage->psalm_internal = $docblock_info->psalm_internal;
|
||||||
|
|
||||||
$storage->sealed_properties = $docblock_info->sealed_properties;
|
|
||||||
$storage->sealed_methods = $docblock_info->sealed_methods;
|
|
||||||
|
|
||||||
if ($docblock_info->mixin) {
|
if ($docblock_info->mixin) {
|
||||||
if (isset($this->class_template_types[$docblock_info->mixin])) {
|
if (isset($this->class_template_types[$docblock_info->mixin])) {
|
||||||
if (IssueBuffer::accepts(
|
if (IssueBuffer::accepts(
|
||||||
@ -1270,17 +1285,6 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
|||||||
$storage->override_method_visibility = $docblock_info->override_method_visibility;
|
$storage->override_method_visibility = $docblock_info->override_method_visibility;
|
||||||
|
|
||||||
$storage->suppressed_issues = $docblock_info->suppressed_issues;
|
$storage->suppressed_issues = $docblock_info->suppressed_issues;
|
||||||
|
|
||||||
foreach ($docblock_info->methods as $method) {
|
|
||||||
/** @var MethodStorage */
|
|
||||||
$pseudo_method_storage = $this->registerFunctionLike($method, true);
|
|
||||||
|
|
||||||
if ($pseudo_method_storage->is_static) {
|
|
||||||
$storage->pseudo_static_methods[strtolower($method->name->name)] = $pseudo_method_storage;
|
|
||||||
} else {
|
|
||||||
$storage->pseudo_methods[strtolower($method->name->name)] = $pseudo_method_storage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,6 @@ class MagicMethodAnnotationTest extends TestCase
|
|||||||
$b = $child->setString(5);
|
$b = $child->setString(5);
|
||||||
$c = $child->getBool("hello");
|
$c = $child->getBool("hello");
|
||||||
$d = $child->getArray();
|
$d = $child->getArray();
|
||||||
$child->setArray(["boo"]);
|
|
||||||
$e = $child->getCallable();
|
$e = $child->getCallable();
|
||||||
$child->setMixed("hello");
|
$child->setMixed("hello");
|
||||||
$child->setMixed(4);
|
$child->setMixed(4);
|
||||||
@ -586,7 +585,6 @@ class MagicMethodAnnotationTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @method string getString()
|
* @method string getString()
|
||||||
* @psalm-seal-methods
|
|
||||||
*/
|
*/
|
||||||
class Child extends ParentClass {}
|
class Child extends ParentClass {}
|
||||||
|
|
||||||
|
@ -40,8 +40,7 @@ class MagicPropertyTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
$a = new A();
|
$a = new A();
|
||||||
$a->foo = "hello";
|
$a->foo = "hello";',
|
||||||
$a->bar = "hello"; // not a property',
|
|
||||||
],
|
],
|
||||||
'propertyOfTypeClassDocblock' => [
|
'propertyOfTypeClassDocblock' => [
|
||||||
'<?php
|
'<?php
|
||||||
@ -449,8 +448,7 @@ class MagicPropertyTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
$a = new A();
|
$a = new A();
|
||||||
$a->foo = "hello";
|
$a->foo = "hello";',
|
||||||
$a->bar = "hello"; // not a property',
|
|
||||||
],
|
],
|
||||||
'overridePropertyAnnotations' => [
|
'overridePropertyAnnotations' => [
|
||||||
'<?php
|
'<?php
|
||||||
@ -479,8 +477,7 @@ class MagicPropertyTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
$a = new A();
|
$a = new A();
|
||||||
$a->foo = "hello";
|
$a->foo = "hello";',
|
||||||
$a->bar = "hello"; // not a property',
|
|
||||||
],
|
],
|
||||||
'overrideWithReadWritePropertyAnnotations' => [
|
'overrideWithReadWritePropertyAnnotations' => [
|
||||||
'<?php
|
'<?php
|
||||||
|
Loading…
Reference in New Issue
Block a user