From 90db017d95ee4092a2f3da593eae28bffa8f1c8b Mon Sep 17 00:00:00 2001 From: Heinz Wiesinger Date: Wed, 24 Apr 2024 13:59:21 +0200 Subject: [PATCH] Allow local phpstan type definitions in class comments --- Lunr/Sniffs/Commenting/ClassCommentSniff.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lunr/Sniffs/Commenting/ClassCommentSniff.php b/Lunr/Sniffs/Commenting/ClassCommentSniff.php index 5df6978..a58d146 100644 --- a/Lunr/Sniffs/Commenting/ClassCommentSniff.php +++ b/Lunr/Sniffs/Commenting/ClassCommentSniff.php @@ -61,6 +61,11 @@ class ClassCommentSniff implements Sniff '@implements' => false, ]; + private $phpstan_tags = [ + '@phpstan-type' => false, + '@phpstan-import-type' => false, + ]; + /** * Returns an array of tokens this test wants to listen for. * @@ -138,6 +143,7 @@ public function process(File $phpcsFile, $stackPtr) $phpunit_tag_keys = array_keys($this->phpunit_tags); $magic_tag_keys = array_keys($this->magic_tags); $generics_tag_keys = array_keys($this->generics_tags); + $phpstan_tag_keys = array_keys($this->phpstan_tags); $handled = []; @@ -165,6 +171,11 @@ public function process(File $phpcsFile, $stackPtr) $handled[] = $name; continue; } + elseif (in_array($name, $phpstan_tag_keys)) + { + $handled[] = $name; + continue; + } $error = '%s tag is not allowed in class comment'; $data = array($tokens[$tag]['content']);