Skip to content

Commit 9b54895

Browse files
geerteltinksimPod
authored andcommitted
Fix intersection type annotations
1 parent f268ca4 commit 9b54895

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
class FunctionCommentSniff implements Sniff
1717
{
18+
const PARAMS_REGEX = '/((?:(?![$.]|&(?=\$)).)*)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/';
1819

1920
/**
2021
* Disable the check for functions with a lower visibility than the value given.
@@ -270,7 +271,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
270271

271272
if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) {
272273
$matches = [];
273-
preg_match('/((?:(?![$.]|&(?=\$)).)*)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches);
274+
preg_match(self::PARAMS_REGEX, $tokens[($tag + 2)]['content'], $matches);
274275

275276
if (empty($matches) === false) {
276277
$typeLen = strlen($matches[1]);

src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
306306
$commentLines = [];
307307
if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) {
308308
$matches = [];
309-
preg_match('/([^$&.]+)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches);
309+
preg_match(self::PARAMS_REGEX, $tokens[($tag + 2)]['content'], $matches);
310310

311311
if (empty($matches) === false) {
312312
$typeLen = strlen($matches[1]);

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc

+11
Original file line numberDiff line numberDiff line change
@@ -1041,3 +1041,14 @@ public function ignored() {
10411041
}
10421042

10431043
// phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct
1044+
1045+
/**
1046+
* @param (Foo&Bar)|null $a Comment.
1047+
* @param string $b Comment.
1048+
*
1049+
* @return void
1050+
*/
1051+
public function setTranslator($a, string &$b): void
1052+
{
1053+
$this->translator = $translator;
1054+
}

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed

+11
Original file line numberDiff line numberDiff line change
@@ -1041,3 +1041,14 @@ public function ignored() {
10411041
}
10421042

10431043
// phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct
1044+
1045+
/**
1046+
* @param (Foo&Bar)|null $a Comment.
1047+
* @param string $b Comment.
1048+
*
1049+
* @return void
1050+
*/
1051+
public function setTranslator($a, string &$b): void
1052+
{
1053+
$this->translator = $translator;
1054+
}

0 commit comments

Comments
 (0)