Skip to content

Commit f4b4580

Browse files
authored
fix(VariableComment): Allow PHP 8.2 style type declarations with parentheses in @var comments (#3395015)
1 parent 032364c commit f4b4580

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ public static function suggestType($type)
952952
// Also allow some more characters for special type hints supported by
953953
// PHPStan:
954954
// https://phpstan.org/writing-php-code/phpdoc-types#basic-types .
955-
$type = preg_replace('/[^a-zA-Z0-9_\\\[\]\-<> ,"\{\}\?\':\*\|\&]/', '', $type);
955+
$type = preg_replace('/[^a-zA-Z0-9_\\\[\]\-<> ,"\{\}\?\':\*\|\&\(\)]/', '', $type);
956956

957957
return $type;
958958

tests/Drupal/Commenting/VariableCommentUnitTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,11 @@ class Test {
102102
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
103103
public string $search_score;
104104

105+
/**
106+
* Allow parentheses in the type declaration.
107+
*
108+
* @var (\Drupal\user\UserInterface&\PHPUnit\Framework\MockObject\MockObject)|null
109+
*/
110+
protected $userMock;
111+
105112
}

tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,11 @@ class Test {
106106
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
107107
public string $search_score;
108108

109+
/**
110+
* Allow parentheses in the type declaration.
111+
*
112+
* @var (\Drupal\user\UserInterface&\PHPUnit\Framework\MockObject\MockObject)|null
113+
*/
114+
protected $userMock;
115+
109116
}

0 commit comments

Comments
 (0)