From dd3fa88b360ffbb7e60304d9aafe94e103427d95 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 29 Nov 2024 23:45:56 +0100 Subject: [PATCH 1/2] chore: check enums for since and experimental comments Signed-off-by: Daniel Kesselberg --- build/psalm/NcuExperimentalChecker.php | 25 +++++++++++++++++-------- build/psalm/OcpSinceChecker.php | 22 ++++++++++++++-------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/build/psalm/NcuExperimentalChecker.php b/build/psalm/NcuExperimentalChecker.php index d5c24333d9ed4..eaa70480ccc63 100644 --- a/build/psalm/NcuExperimentalChecker.php +++ b/build/psalm/NcuExperimentalChecker.php @@ -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; @@ -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'); + } } } @@ -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) { diff --git a/build/psalm/OcpSinceChecker.php b/build/psalm/OcpSinceChecker.php index c030678aee1b1..959e70e0c4ce6 100644 --- a/build/psalm/OcpSinceChecker.php +++ b/build/psalm/OcpSinceChecker.php @@ -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'); + } } } @@ -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) { From f2d0f7971076b571998c37b0bb516650377ea83f Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 2 Dec 2024 14:29:43 +0100 Subject: [PATCH 2/2] chore: mark enums in value type as experimental Signed-off-by: Daniel Kesselberg --- lib/unstable/Config/ValueType.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/unstable/Config/ValueType.php b/lib/unstable/Config/ValueType.php index 9f49f7241f85b..eddfda4c14e5f 100644 --- a/lib/unstable/Config/ValueType.php +++ b/lib/unstable/Config/ValueType.php @@ -18,17 +18,35 @@ * @since 31.0.0 */ enum ValueType: int { - /** @since 31.0.0 */ + /** + * @experimental 31.0.0 + * @since 31.0.0 + */ case MIXED = 0; - /** @since 31.0.0 */ + /** + * @experimental 31.0.0 + * @since 31.0.0 + */ case STRING = 1; - /** @since 31.0.0 */ + /** + * @experimental 31.0.0 + * @since 31.0.0 + */ case INT = 2; - /** @since 31.0.0 */ + /** + * @experimental 31.0.0 + * @since 31.0.0 + */ case FLOAT = 3; - /** @since 31.0.0 */ + /** + * @experimental 31.0.0 + * @since 31.0.0 + */ case BOOL = 4; - /** @since 31.0.0 */ + /** + * @experimental 31.0.0 + * @since 31.0.0 + */ case ARRAY = 5; /**