fix(OCP): Check for typos in "deprecated"

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2024-02-14 17:28:38 +01:00
parent f14949218c
commit 887c061fc8
No known key found for this signature in database
GPG Key ID: 74434EFE0D2E2205
1 changed files with 26 additions and 4 deletions

View File

@ -39,7 +39,11 @@ class OcpSinceChecker implements Psalm\Plugin\EventHandler\AfterClassLikeVisitIn
self::checkClassComment($stmt, $statementsSource);
foreach ($stmt->getMethods() as $method) {
self::checkMethodComment($method, $statementsSource);
self::checkMethodOrConstantComment($method, $statementsSource, 'method');
}
foreach ($stmt->getConstants() as $constant) {
self::checkMethodOrConstantComment($constant, $statementsSource, 'constant');
}
}
@ -76,15 +80,24 @@ class OcpSinceChecker implements Psalm\Plugin\EventHandler\AfterClassLikeVisitIn
)
);
}
if (isset($parsedDocblock->tags['depreacted'])) {
IssueBuffer::maybeAdd(
new InvalidDocblock(
'Typo in @deprecated for classes/interfaces in OCP.',
new CodeLocation($statementsSource, $stmt)
)
);
}
}
private static function checkMethodComment(Stmt $stmt, FileSource $statementsSource): void {
private static function checkMethodOrConstantComment(Stmt $stmt, FileSource $statementsSource, string $type): void {
$docblock = $stmt->getDocComment();
if ($docblock === null) {
IssueBuffer::maybeAdd(
new InvalidDocblock(
'PHPDoc is required for methods in OCP.',
'PHPDoc is required for ' . $type . 's in OCP.',
new CodeLocation($statementsSource, $stmt)
),
);
@ -106,7 +119,16 @@ class OcpSinceChecker implements Psalm\Plugin\EventHandler\AfterClassLikeVisitIn
if (!isset($parsedDocblock->tags['since'])) {
IssueBuffer::maybeAdd(
new InvalidDocblock(
'@since is required for methods in OCP.',
'@since is required for ' . $type . 's in OCP.',
new CodeLocation($statementsSource, $stmt)
)
);
}
if (isset($parsedDocblock->tags['depreacted'])) {
IssueBuffer::maybeAdd(
new InvalidDocblock(
'Typo in @deprecated for ' . $type . ' in OCP.',
new CodeLocation($statementsSource, $stmt)
)
);