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

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/43581/head
Joas Schilling 4 months ago
parent f14949218c
commit 887c061fc8
No known key found for this signature in database
GPG Key ID: 74434EFE0D2E2205

@ -39,7 +39,11 @@ class OcpSinceChecker implements Psalm\Plugin\EventHandler\AfterClassLikeVisitIn
self::checkClassComment($stmt, $statementsSource); self::checkClassComment($stmt, $statementsSource);
foreach ($stmt->getMethods() as $method) { 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(); $docblock = $stmt->getDocComment();
if ($docblock === null) { if ($docblock === null) {
IssueBuffer::maybeAdd( IssueBuffer::maybeAdd(
new InvalidDocblock( new InvalidDocblock(
'PHPDoc is required for methods in OCP.', 'PHPDoc is required for ' . $type . 's in OCP.',
new CodeLocation($statementsSource, $stmt) new CodeLocation($statementsSource, $stmt)
), ),
); );
@ -106,7 +119,16 @@ class OcpSinceChecker implements Psalm\Plugin\EventHandler\AfterClassLikeVisitIn
if (!isset($parsedDocblock->tags['since'])) { if (!isset($parsedDocblock->tags['since'])) {
IssueBuffer::maybeAdd( IssueBuffer::maybeAdd(
new InvalidDocblock( 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) new CodeLocation($statementsSource, $stmt)
) )
); );

Loading…
Cancel
Save