Skip to content

Commit

Permalink
Fix intersection type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
geerteltink authored and simPod committed Nov 15, 2021
1 parent 5fb9b64 commit 5aa4ee6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
11 changes: 11 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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, &$b): void
{
$this->translator = $translator;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, &$b): void
{
$this->translator = $translator;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function getErrorList()
792 => 1,
794 => 1,
797 => 1,
801 => 1,
828 => 1,
840 => 1,
852 => 1,
Expand Down Expand Up @@ -131,6 +130,7 @@ public function getErrorList()
$errors[575] = 2;
$errors[627] = 1;
$errors[1002] = 1;
$errors[1051] = 1;
} else {
$errors[729] = 4;
$errors[740] = 2;
Expand Down

0 comments on commit 5aa4ee6

Please sign in to comment.