1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #134 - warn when docblock type is ill-formatted

This commit is contained in:
Matthew Brown 2017-05-24 21:11:18 -04:00
parent 77a44051c5
commit 42b435e23f
2 changed files with 22 additions and 0 deletions

View File

@ -143,6 +143,10 @@ class CommentChecker
&& !strpos($line_parts[0], '::') && !strpos($line_parts[0], '::')
&& $line_parts[0][0] !== '{' && $line_parts[0][0] !== '{'
) { ) {
if ($line_parts[0][0] === '$' && $line_parts[0] !== '$this') {
throw new DocblockParseException('Badly-formatted @param type');
}
$info->return_type = $line_parts[0]; $info->return_type = $line_parts[0];
$line_number = array_keys($return_specials)[0]; $line_number = array_keys($return_specials)[0];
@ -176,6 +180,10 @@ class CommentChecker
$line_parts[1] = substr($line_parts[1], 1); $line_parts[1] = substr($line_parts[1], 1);
} }
if ($line_parts[0][0] === '$' && $line_parts[0] !== '$this') {
throw new DocblockParseException('Badly-formatted @param type');
}
$line_parts[1] = preg_replace('/,$/', '', $line_parts[1]); $line_parts[1] = preg_replace('/,$/', '', $line_parts[1]);
$info->params[] = [ $info->params[] = [
@ -290,6 +298,10 @@ class CommentChecker
$line_parts[1] = substr($line_parts[1], 1); $line_parts[1] = substr($line_parts[1], 1);
} }
if ($line_parts[0][0] === '$' && $line_parts[0] !== '$this') {
throw new DocblockParseException('Badly-formatted @param type');
}
$line_parts[1] = preg_replace('/,$/', '', $line_parts[1]); $line_parts[1] = preg_replace('/,$/', '', $line_parts[1]);
$info->properties[] = [ $info->properties[] = [

View File

@ -173,6 +173,16 @@ class AnnotationTest extends TestCase
public function providerFileCheckerInvalidCodeParse() public function providerFileCheckerInvalidCodeParse()
{ {
return [ return [
'invalidReturn' => [
'<?php
interface I {
/**
* @return $thus
*/
public static function barBar();
}',
'error_message' => 'InvalidDocblock'
],
'deprecatedMethodWithCall' => [ 'deprecatedMethodWithCall' => [
'<?php '<?php
class Foo { class Foo {