From aa250cbc831a03ec3a32a6801219a1f17b728ad2 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Wed, 1 Jan 2025 19:52:47 +0100 Subject: [PATCH] fix(VariableComment): Allow PHP 8.2 style type declarations with parentheses in @var comments --- .../Drupal/Sniffs/Commenting/FunctionCommentSniff.php | 2 +- tests/Drupal/Commenting/VariableCommentUnitTest.inc | 7 +++++++ tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php index 8db59805..cc55d038 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php @@ -952,7 +952,7 @@ public static function suggestType($type) // Also allow some more characters for special type hints supported by // PHPStan: // https://phpstan.org/writing-php-code/phpdoc-types#basic-types . - $type = preg_replace('/[^a-zA-Z0-9_\\\[\]\-<> ,"\{\}\?\':\*\|\&]/', '', $type); + $type = preg_replace('/[^a-zA-Z0-9_\\\[\]\-<> ,"\{\}\?\':\*\|\&\(\)]/', '', $type); return $type; diff --git a/tests/Drupal/Commenting/VariableCommentUnitTest.inc b/tests/Drupal/Commenting/VariableCommentUnitTest.inc index e11a53d0..d0e8e873 100644 --- a/tests/Drupal/Commenting/VariableCommentUnitTest.inc +++ b/tests/Drupal/Commenting/VariableCommentUnitTest.inc @@ -102,4 +102,11 @@ class Test { // phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName public string $search_score; + /** + * Allow parentheses in the type declaration. + * + * @var (\Drupal\user\UserInterface&\PHPUnit\Framework\MockObject\MockObject)|null + */ + protected $userMock; + } diff --git a/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed b/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed index b2d9c1f4..c0f26b08 100644 --- a/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed +++ b/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed @@ -106,4 +106,11 @@ class Test { // phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName public string $search_score; + /** + * Allow parentheses in the type declaration. + * + * @var (\Drupal\user\UserInterface&\PHPUnit\Framework\MockObject\MockObject)|null + */ + protected $userMock; + }