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 Jan 13, 2022
1 parent cfdc6c9 commit 10e6e2e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 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 @@ -308,7 +308,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
13 changes: 12 additions & 1 deletion src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,18 @@ public function ignored() {

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

/**
/**
* @return void
* @throws Exception If any other error occurs. */
function throwCommentOneLine() {}

/**
* @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 @@ -1042,7 +1042,18 @@ public function ignored() {

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

/**
/**
* @return void
* @throws Exception If any other error occurs. */
function throwCommentOneLine() {}

/**
* @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[1056] = 1;
} else {
$errors[729] = 4;
$errors[740] = 2;
Expand Down

0 comments on commit 10e6e2e

Please sign in to comment.