Skip to content
Permalink
Browse files

Seal properties and methods whenever @method/@Property is used

  • Loading branch information
muglug committed Jan 3, 2020
1 parent bf310fb commit df33405635cbdb6d41474503ca20c8adda55d438
@@ -1196,6 +1196,9 @@ function (array $l, array $r) : int {
$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) {
foreach ($docblock_info->properties as $property) {
$pseudo_property_type_tokens = Type::fixUpLocalType(
@@ -1233,15 +1236,27 @@ function (array $l, array $r) : int {
$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->internal = $docblock_info->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 (isset($this->class_template_types[$docblock_info->mixin])) {
if (IssueBuffer::accepts(
@@ -1270,17 +1285,6 @@ function (array $l, array $r) : int {
$storage->override_method_visibility = $docblock_info->override_method_visibility;

$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 Child extends ParentClass {}
$b = $child->setString(5);
$c = $child->getBool("hello");
$d = $child->getArray();
$child->setArray(["boo"]);
$e = $child->getCallable();
$child->setMixed("hello");
$child->setMixed(4);
@@ -586,7 +585,6 @@ public function __call(string $name, array $args) {}
/**
* @method string getString()
* @psalm-seal-methods
*/
class Child extends ParentClass {}
@@ -40,8 +40,7 @@ public function __set($name, $value): void {
}
$a = new A();
$a->foo = "hello";
$a->bar = "hello"; // not a property',
$a->foo = "hello";',
],
'propertyOfTypeClassDocblock' => [
'<?php
@@ -449,8 +448,7 @@ public function __set($name, $value): void {
}
$a = new A();
$a->foo = "hello";
$a->bar = "hello"; // not a property',
$a->foo = "hello";',
],
'overridePropertyAnnotations' => [
'<?php
@@ -479,8 +477,7 @@ public function __set($name, $value): void {
}
$a = new A();
$a->foo = "hello";
$a->bar = "hello"; // not a property',
$a->foo = "hello";',
],
'overrideWithReadWritePropertyAnnotations' => [
'<?php

0 comments on commit df33405

Please sign in to comment.
You can’t perform that action at this time.