Skip to content

Commit 6567e47

Browse files
geerteltinksimPod
authored andcommitted
Fix intersection type annotations
1 parent dd8a709 commit 6567e47

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
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
@@ -308,7 +308,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
308308
$commentLines = [];
309309
if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) {
310310
$matches = [];
311-
preg_match('/([^$&.]+)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches);
311+
preg_match(self::PARAMS_REGEX, $tokens[($tag + 2)]['content'], $matches);
312312

313313
if (empty($matches) === false) {
314314
$typeLen = strlen($matches[1]);

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,18 @@ public function ignored() {
10421042

10431043
// phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct
10441044

1045-
/**
1045+
/**
10461046
* @return void
10471047
* @throws Exception If any other error occurs. */
10481048
function throwCommentOneLine() {}
1049+
1050+
/**
1051+
* @param (Foo&Bar)|null $a Comment.
1052+
* @param string $b Comment.
1053+
*
1054+
* @return void
1055+
*/
1056+
public function setTranslator($a, &$b): void
1057+
{
1058+
$this->translator = $translator;
1059+
}

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,18 @@ public function ignored() {
10421042

10431043
// phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct
10441044

1045-
/**
1045+
/**
10461046
* @return void
10471047
* @throws Exception If any other error occurs. */
10481048
function throwCommentOneLine() {}
1049+
1050+
/**
1051+
* @param (Foo&Bar)|null $a Comment.
1052+
* @param string $b Comment.
1053+
*
1054+
* @return void
1055+
*/
1056+
public function setTranslator($a, &$b): void
1057+
{
1058+
$this->translator = $translator;
1059+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public function getErrorList()
103103
792 => 1,
104104
794 => 1,
105105
797 => 1,
106-
801 => 1,
107106
828 => 1,
108107
840 => 1,
109108
852 => 1,
@@ -131,6 +130,7 @@ public function getErrorList()
131130
$errors[575] = 2;
132131
$errors[627] = 1;
133132
$errors[1002] = 1;
133+
$errors[1056] = 1;
134134
} else {
135135
$errors[729] = 4;
136136
$errors[740] = 2;

0 commit comments

Comments
 (0)