Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip processing of Squiz.Commenting.FunctionComment for @inheritDoc #3533

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ protected function checkSpacingAfterParamName(File $phpcsFile, $param, $maxVar,
* in the stack passed in $tokens.
* @param int $commentStart The position in the stack where the comment started.
*
* @return boolean TRUE if the docblock contains only {@inheritdoc} (case-insensitive).
* @return boolean TRUE if the docblock contains {@inheritdoc} or @inheritdoc (case-insensitive).
*/
protected function checkInheritdoc(File $phpcsFile, $stackPtr, $commentStart)
{
Expand All @@ -752,11 +752,7 @@ protected function checkInheritdoc(File $phpcsFile, $stackPtr, $commentStart)
if (in_array($tokens[$i]['code'], $allowedTokens) === false) {
$trimmedContent = strtolower(trim($tokens[$i]['content']));

if ($trimmedContent === '{@inheritdoc}') {
return true;
} else {
return false;
}
return $trimmedContent === '{@inheritdoc}' || $trimmedContent === '@inheritdoc';
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1006,13 +1006,23 @@ function foo($foo) {}
*/
public function foo($a, $b) {}

/**
* @inheritDoc
*/
public function foo($a, $b) {}

// phpcs:set Squiz.Commenting.FunctionComment skipIfInheritdoc true

/**
* {@inheritDoc}
*/
public function foo($a, $b) {}

/**
* @inheritDoc
*/
public function foo($a, $b) {}

/**
* Foo.
*
Expand Down Expand Up @@ -1042,7 +1052,7 @@ public function ignored() {

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

/**
PavelSavushkinMix marked this conversation as resolved.
Show resolved Hide resolved
/**
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
/**

* @return void
* @throws Exception If any other error occurs. */
function throwCommentOneLine() {}
Original file line number Diff line number Diff line change
Expand Up @@ -1006,13 +1006,23 @@ function foo($foo) {}
*/
public function foo($a, $b) {}

/**
* @inheritDoc
*/
public function foo($a, $b) {}

// phpcs:set Squiz.Commenting.FunctionComment skipIfInheritdoc true

/**
* {@inheritDoc}
*/
public function foo($a, $b) {}

/**
* @inheritDoc
*/
public function foo($a, $b) {}

/**
* Foo.
*
Expand Down Expand Up @@ -1042,7 +1052,7 @@ public function ignored() {

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

/**
/**
* @return void
* @throws Exception If any other error occurs. */
function throwCommentOneLine() {}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public function getErrorList()
997 => 1,
1004 => 2,
1006 => 1,
1029 => 1,
1009 => 2,
1011 => 1,
1039 => 1,
];

// Scalar type hints only work from PHP 7 onwards.
Expand Down Expand Up @@ -151,7 +153,7 @@ public function getErrorList()
$errors[459] = 1;
$errors[893] = 3;
} else {
$errors[1023] = 1;
$errors[1033] = 1;
}

return $errors;
Expand Down