Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VariableComment): Allow PHP 8.2 style type declarations with parentheses in @var comments #248

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions tests/Drupal/Commenting/VariableCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
7 changes: 7 additions & 0 deletions tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Loading