mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #789 - allow union types in @method params
This commit is contained in:
parent
e53783f8f4
commit
51e7042022
@ -385,6 +385,8 @@ class CommentChecker
|
||||
$method_entry = substr($method_entry, 0, (int) $matches[0][1] + strlen((string) $matches[0][0]));
|
||||
}
|
||||
|
||||
$method_entry = str_replace('|', '__UNIONOR__', $method_entry);
|
||||
|
||||
$php_string = '<?php ' . $return_docblock . ' function ' . $method_entry . '{}';
|
||||
|
||||
try {
|
||||
|
@ -1265,6 +1265,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
|
||||
}
|
||||
|
||||
if ($param_type_string) {
|
||||
$param_type_string = str_replace('__UNIONOR__', '|', $param_type_string);
|
||||
if ($is_nullable) {
|
||||
$param_type_string .= '|null';
|
||||
}
|
||||
|
@ -745,6 +745,7 @@ class AnnotationTest extends TestCase
|
||||
* @method void setInteger(int $integer)
|
||||
* @method setString(int $integer)
|
||||
* @method getBool(string $foo) : bool
|
||||
* @method setBool(string $foo, string|bool $bar) : bool
|
||||
* @method (string|int)[] getArray() : array with some text
|
||||
* @method void setArray(array $arr = array(), int $foo = 5) with some more text
|
||||
* @method (callable() : string) getCallable() : callable
|
||||
@ -758,6 +759,8 @@ class AnnotationTest extends TestCase
|
||||
/** @psalm-suppress MixedAssignment */
|
||||
$b = $child->setString(5);
|
||||
$c = $child->getBool("hello");
|
||||
$c = $child->setBool("hello", true);
|
||||
$c = $child->setBool("hello", "true");
|
||||
$d = $child->getArray();
|
||||
$child->setArray(["boo"])
|
||||
$e = $child->getCallable();',
|
||||
@ -1296,18 +1299,6 @@ class AnnotationTest extends TestCase
|
||||
class Child extends Parent {}',
|
||||
'error_message' => 'InvalidDocblock',
|
||||
],
|
||||
'magicMethodAnnotationWithUnionTypeInDocblock' => [
|
||||
'<?php
|
||||
class Parent {
|
||||
public function __call() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method string getString(string|int $x)
|
||||
*/
|
||||
class Child extends Parent {}',
|
||||
'error_message' => 'InvalidDocblock',
|
||||
],
|
||||
'magicMethodAnnotationWithSealed' => [
|
||||
'<?php
|
||||
class Parent {
|
||||
|
Loading…
Reference in New Issue
Block a user