From 5aca79ee52a179fc17f0335ed31e463ec67f2cb2 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Sun, 29 Mar 2020 15:20:00 +0200 Subject: [PATCH] Fix intersection type annotations --- .../PEAR/Sniffs/Commenting/FunctionCommentSniff.php | 3 ++- .../Squiz/Sniffs/Commenting/FunctionCommentSniff.php | 2 +- .../Tests/Commenting/FunctionCommentUnitTest.inc | 11 +++++++++++ .../Commenting/FunctionCommentUnitTest.inc.fixed | 11 +++++++++++ .../Tests/Commenting/FunctionCommentUnitTest.php | 1 - 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php index 408856fc5a..a9fbf173f2 100644 --- a/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php @@ -15,6 +15,7 @@ class FunctionCommentSniff implements Sniff { + const PARAMS_REGEX = '/((?:(?![$.]|&(?=\$)).)*)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/'; /** * Disable the check for functions with a lower visibility than the value given. @@ -270,7 +271,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { $matches = []; - preg_match('/((?:(?![$.]|&(?=\$)).)*)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches); + preg_match(self::PARAMS_REGEX, $tokens[($tag + 2)]['content'], $matches); if (empty($matches) === false) { $typeLen = strlen($matches[1]); diff --git a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php index a23032e280..4ca880331f 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php @@ -306,7 +306,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) $commentLines = []; if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { $matches = []; - preg_match('/([^$&.]+)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches); + preg_match(self::PARAMS_REGEX, $tokens[($tag + 2)]['content'], $matches); if (empty($matches) === false) { $typeLen = strlen($matches[1]); diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc index deaa966eae..7d5c5485d7 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc @@ -1041,3 +1041,14 @@ public function ignored() { } // phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct + +/** + * @param (Foo&Bar)|null $a Comment. + * @param string $b Comment. + * + * @return void + */ +public function setTranslator($a, string &$b): void +{ + $this->translator = $translator; +} diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed index b46df26b54..da97dfbc18 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed @@ -1041,3 +1041,14 @@ public function ignored() { } // phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct + +/** + * @param (Foo&Bar)|null $a Comment. + * @param string $b Comment. + * + * @return void + */ +public function setTranslator($a, string &$b): void +{ + $this->translator = $translator; +} diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php index 632b7c51b2..024a57a0e2 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php @@ -103,7 +103,6 @@ public function getErrorList() 792 => 1, 794 => 1, 797 => 1, - 801 => 1, 828 => 1, 840 => 1, 852 => 1,