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 Oct 25, 2021
1 parent f268ca4 commit 5aca79e
Show file tree
Hide file tree
Showing 5 changed files with 25 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, string &$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, string &$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

0 comments on commit 5aca79e

Please sign in to comment.