mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Update docblock checker to see object-like types
This commit is contained in:
parent
e14cadd32e
commit
7565ee3fac
@ -8,7 +8,7 @@ use Psalm\Type;
|
||||
|
||||
class CommentChecker
|
||||
{
|
||||
const TYPE_REGEX = '(\\\?[A-Za-z0-9_\<,\>\[\]|\\\]+[A-Za-z0-9_\<,\>\[\]]|\$[a-zA-Z_0-9_\<,\>\|\[\]]+)';
|
||||
const TYPE_REGEX = '(\\\?[A-Za-z0-9_\<,\>\[\]\-\{\}:|\\\]+[A-Za-z0-9_\<,\>\[\]-\{\}:]|\$[a-zA-Z_0-9_\<,\>\|\[\]-\{\}:]+)';
|
||||
|
||||
/**
|
||||
* @param string $comment
|
||||
@ -65,7 +65,9 @@ class CommentChecker
|
||||
if (isset($comments['specials']['return'])) {
|
||||
$return_blocks = preg_split('/[\s]+/', $comments['specials']['return'][0]);
|
||||
|
||||
if (preg_match('/^' . self::TYPE_REGEX . '$/', $return_blocks[0]) && !preg_match('/\[[^\]]+\]/', $return_blocks[0])) {
|
||||
if (preg_match('/^' . self::TYPE_REGEX . '$/', $return_blocks[0])
|
||||
&& !preg_match('/\[[^\]]+\]/', $return_blocks[0])
|
||||
&& !strpos($return_blocks[0], '::')) {
|
||||
$info['return_type'] = $return_blocks[0];
|
||||
}
|
||||
}
|
||||
@ -74,10 +76,11 @@ class CommentChecker
|
||||
foreach ($comments['specials']['param'] as $param) {
|
||||
$param_blocks = preg_split('/[\s]+/', $param);
|
||||
|
||||
if (count($param_blocks) > 1 &&
|
||||
preg_match('/^' . self::TYPE_REGEX . '$/', $param_blocks[0]) &&
|
||||
!preg_match('/\[[^\]]+\]/', $param_blocks[0]) &&
|
||||
preg_match('/^\$[A-Za-z0-9_]+$/', $param_blocks[1])
|
||||
if (count($param_blocks) > 1
|
||||
&& preg_match('/^' . self::TYPE_REGEX . '$/', $param_blocks[0])
|
||||
&& !preg_match('/\[[^\]]+\]/', $param_blocks[0])
|
||||
&& preg_match('/^\$[A-Za-z0-9_]+$/', $param_blocks[1])
|
||||
&& !strpos($param_blocks[0], '::')
|
||||
) {
|
||||
$info['params'][] = ['name' => substr($param_blocks[1], 1), 'type' => $param_blocks[0]];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user