mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Allow @psalm-property and @psalm-method
This commit is contained in:
parent
34b333cf7f
commit
68a135f434
@ -128,6 +128,7 @@ class DocComment
|
||||
$special_key,
|
||||
[
|
||||
'return', 'param', 'template', 'var', 'type',
|
||||
'property', 'method',
|
||||
'assert', 'assert-if-true', 'assert-if-false', 'suppress',
|
||||
'ignore-nullable-return', 'override-property-visibility',
|
||||
'override-method-visibility', 'seal-properties', 'seal-methods',
|
||||
|
@ -613,8 +613,11 @@ class CommentAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($comments['specials']['method'])) {
|
||||
foreach ($comments['specials']['method'] as $method_entry) {
|
||||
if (isset($comments['specials']['method']) || isset($comments['specials']['psalm-method'])) {
|
||||
$all_methods = (isset($comments['specials']['method']) ? $comments['specials']['method'] : [])
|
||||
+ (isset($comments['specials']['psalm-method']) ? $comments['specials']['psalm-method'] : []);
|
||||
|
||||
foreach ($all_methods as $method_entry) {
|
||||
$method_entry = preg_replace('/[ \t]+/', ' ', trim($method_entry));
|
||||
|
||||
$docblock_lines = [];
|
||||
@ -714,6 +717,7 @@ class CommentAnalyzer
|
||||
}
|
||||
|
||||
self::addMagicPropertyToInfo($info, $comments['specials'], 'property');
|
||||
self::addMagicPropertyToInfo($info, $comments['specials'], 'psalm-property');
|
||||
self::addMagicPropertyToInfo($info, $comments['specials'], 'property-read');
|
||||
self::addMagicPropertyToInfo($info, $comments['specials'], 'property-write');
|
||||
|
||||
@ -723,7 +727,7 @@ class CommentAnalyzer
|
||||
/**
|
||||
* @param ClassLikeDocblockComment $info
|
||||
* @param array<string, array<int, string>> $specials
|
||||
* @param string $property_tag ('property', 'property-read', or 'property-write')
|
||||
* @param string $property_tag ('property', 'psalm-property', 'property-read', or 'property-write')
|
||||
*
|
||||
* @throws DocblockParseException
|
||||
*
|
||||
|
@ -386,6 +386,26 @@ class MagicMethodAnnotationTest extends TestCase
|
||||
'$d' => 'D',
|
||||
]
|
||||
],
|
||||
'validSimplePsalmAnnotations' => [
|
||||
'<?php
|
||||
class ParentClass {
|
||||
public function __call(string $name, array $args) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-method string getString() dsa sada
|
||||
* @psalm-method void setInteger(int $integer) dsa sada
|
||||
*/
|
||||
class Child extends ParentClass {}
|
||||
|
||||
$child = new Child();
|
||||
|
||||
$a = $child->getString();
|
||||
$child->setInteger(4);',
|
||||
'assertions' => [
|
||||
'$a' => 'string',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -405,6 +405,35 @@ class MagicPropertyTest extends TestCase
|
||||
$o->foo = "hello";
|
||||
}',
|
||||
],
|
||||
'psalmPropertyDocblock' => [
|
||||
'<?php
|
||||
namespace Bar;
|
||||
|
||||
/**
|
||||
* @psalm-property string $foo
|
||||
*/
|
||||
class A {
|
||||
/** @param string $name */
|
||||
public function __get($name): ?string {
|
||||
if ($name === "foo") {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value): void {
|
||||
}
|
||||
}
|
||||
|
||||
$a = new A();
|
||||
$a->foo = "hello";
|
||||
$a->bar = "hello"; // not a property',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user