1
0
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:
Matt Brown 2018-06-05 17:59:32 -04:00
parent e53783f8f4
commit 51e7042022
3 changed files with 6 additions and 12 deletions

View File

@ -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 {

View File

@ -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';
}

View File

@ -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 {