1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Add support for ?A types in docblock

This commit is contained in:
Matthew Brown 2017-01-16 19:17:46 -05:00
parent 9220b958eb
commit 317eab8730
2 changed files with 21 additions and 1 deletions

View File

@ -11,7 +11,7 @@ use Psalm\Type;
class CommentChecker
{
const TYPE_REGEX =
'(\\\?[A-Za-z0-9_\<,\>\[\]\-\{\}:|\\\]+|\$[a-zA-Z_0-9_\<,\>\|\[\]-\{\}:]+)';
'(\??\\\?[A-Za-z0-9_\<,\>\[\]\-\{\}:|\\\]+|\$[a-zA-Z_0-9_\<,\>\|\[\]-\{\}:]+)';
/**
* @param string $comment

View File

@ -55,6 +55,26 @@ class Php71Test extends PHPUnit_Framework_TestCase
$this->assertEquals('string|null', (string) $context->vars_in_scope['$a']);
}
/**
* @return void
*/
public function testNullableReturnTypeInDocblock()
{
$stmts = self::$parser->parse('<?php
/** @return ?string */
function a() {
return rand(0, 10) ? "elePHPant" : null;
}
$a = a();
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
$this->assertEquals('null|string', (string) $context->vars_in_scope['$a']);
}
/**
* @return void
*/