Skip to content

Commit

Permalink
chore: check enums for since and experimental comments
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Nov 29, 2024
1 parent a4502b0 commit 928b1f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
25 changes: 17 additions & 8 deletions build/psalm/NcuExperimentalChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/

use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\EnumCase;
use Psalm\CodeLocation;
use Psalm\DocComment;
use Psalm\Exception\DocblockParseException;
Expand All @@ -18,17 +21,23 @@

class NcuExperimentalChecker implements Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface {
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void {
$stmt = $event->getStmt();
$classLike = $event->getStmt();
$statementsSource = $event->getStatementsSource();

self::checkClassComment($stmt, $statementsSource);
self::checkClassComment($classLike, $statementsSource);

foreach ($stmt->getMethods() as $method) {
self::checkMethodOrConstantComment($method, $statementsSource, 'method');
}
foreach ($classLike->stmts as $stmt) {
if ($stmt instanceof ClassConst) {
self::checkStatementComment($stmt, $statementsSource, 'constant');
}

if ($stmt instanceof ClassMethod) {
self::checkStatementComment($stmt, $statementsSource, 'method');
}

foreach ($stmt->getConstants() as $constant) {
self::checkMethodOrConstantComment($constant, $statementsSource, 'constant');
if ($stmt instanceof EnumCase) {
self::checkStatementComment($stmt, $statementsSource, 'enum');
}
}
}

Expand Down Expand Up @@ -76,7 +85,7 @@ private static function checkClassComment(ClassLike $stmt, FileSource $statement
}
}

private static function checkMethodOrConstantComment(Stmt $stmt, FileSource $statementsSource, string $type): void {
private static function checkStatementComment(Stmt $stmt, FileSource $statementsSource, string $type): void {
$docblock = $stmt->getDocComment();

if ($docblock === null) {
Expand Down
22 changes: 14 additions & 8 deletions build/psalm/OcpSinceChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,23 @@

class OcpSinceChecker implements Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface {
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void {
$stmt = $event->getStmt();
$classLike = $event->getStmt();
$statementsSource = $event->getStatementsSource();

self::checkClassComment($stmt, $statementsSource);
self::checkClassComment($classLike, $statementsSource);

foreach ($stmt->getMethods() as $method) {
self::checkMethodOrConstantComment($method, $statementsSource, 'method');
}
foreach ($classLike->stmts as $stmt) {
if ($stmt instanceof ClassConst) {
self::checkStatementComment($stmt, $statementsSource, 'constant');
}

if ($stmt instanceof ClassMethod) {
self::checkStatementComment($stmt, $statementsSource, 'method');
}

foreach ($stmt->getConstants() as $constant) {
self::checkMethodOrConstantComment($constant, $statementsSource, 'constant');
if ($stmt instanceof EnumCase) {
self::checkStatementComment($stmt, $statementsSource, 'enum');
}
}
}

Expand Down Expand Up @@ -75,7 +81,7 @@ private static function checkClassComment(ClassLike $stmt, FileSource $statement
}
}

private static function checkMethodOrConstantComment(Stmt $stmt, FileSource $statementsSource, string $type): void {
private static function checkStatementComment(Stmt $stmt, FileSource $statementsSource, string $type): void {
$docblock = $stmt->getDocComment();

if ($docblock === null) {
Expand Down

0 comments on commit 928b1f1

Please sign in to comment.