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

Prevent @property annotations on class properties

This commit is contained in:
piporoid 2021-08-10 21:57:58 +09:00
parent 2e7763c314
commit 1df5f3012a
2 changed files with 15 additions and 0 deletions

View File

@ -1282,6 +1282,13 @@ class ClassLikeNodeScanner
$property_is_initialized = true;
}
if (preg_match('/[ \t\*]+@property[ \t]+/', (string)$comment)) {
$storage->docblock_issues[] = new InvalidDocblock(
'@property is valid only in docblocks for class',
new CodeLocation($this->file_scanner, $stmt, null, true)
);
}
try {
$var_comments = CommentAnalyzer::getTypeFromComment(
$comment,

View File

@ -1146,6 +1146,14 @@ class MagicPropertyTest extends TestCase
}',
'error_message' => 'UndefinedMagicPropertyAssignment',
],
'propertyDocblockOnProperty' => [
'<?php
class A {
/** @property string[] */
public array $arr;
}',
'error_message' => 'InvalidDocblock'
],
];
}
}