-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
phpcs error on rule classes - must be of the type integer #22947
Conversation
Hi @Nazar65. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
$phpcsFile->addError('Comment block is missing', $stackPtr -1, 'MethodArguments'); | ||
return; | ||
} | ||
$this->validateAnnotationBlockExists($phpcsFile, $previousCommentClosePtr, (int)$stackPtr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this cast to (int)
still necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur Nope, can i remove it ?
@@ -663,6 +663,10 @@ private function noneParamsAligned(array $argumentPositions, array $commentPosit | |||
foreach ($argumentPositions as $index => $argumentPosition) { | |||
$commentPosition = $commentPositions[$index]; | |||
$type = $paramDefinitions[$index]['type']; | |||
if ($type == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur Found one new issue in dev branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add more info - I'm more suspicious about the unset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur well, unset is not needed, when we have type null, we can just skip iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, please do so and also make a check strict (=== null
).
@@ -663,6 +663,10 @@ private function noneParamsAligned(array $argumentPositions, array $commentPosit | |||
foreach ($argumentPositions as $index => $argumentPosition) { | |||
$commentPosition = $commentPositions[$index]; | |||
$type = $paramDefinitions[$index]['type']; | |||
if ($type == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, please do so and also make a check strict (=== null
).
@orlangur done ✔️ |
Hi @orlangur, thank you for the review. |
✔️ QA Passed |
@Nazar65 The exact same problem is present in the You can use this class to test. <?php
class Foo {
public function bar()
{
return 0;
}
} The run the sniffs with
|
dev/tests/static/framework/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php
Show resolved
Hide resolved
@@ -97,8 +97,12 @@ public function process(File $phpcsFile, $stackPtr) | |||
{ | |||
$tokens = $phpcsFile->getTokens(); | |||
$previousCommentClosePtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1, 0); | |||
$this->validateAnnotationBlockExists($phpcsFile, (int)$previousCommentClosePtr, (int)$stackPtr); | |||
$commentStartPtr = (int)$phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, 0); | |||
if ($previousCommentClosePtr === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert.
@@ -45,6 +45,10 @@ public function process(File $phpcsFile, $stackPtr) | |||
$tokens = $phpcsFile->getTokens(); | |||
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, ($stackPtr), 0); | |||
$commentEndPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr), 0); | |||
if ($commentStartPtr === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert.
@@ -550,8 +550,12 @@ public function process(File $phpcsFile, $stackPtr) | |||
$numTokens = count($tokens); | |||
$previousCommentOpenPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, 0); | |||
$previousCommentClosePtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1, 0); | |||
if (!$this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)) { | |||
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments'); | |||
if ($previousCommentClosePtr !== false && $previousCommentOpenPtr !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert.
@orlangur done ✔️ |
Hi @orlangur, thank you for the review. |
✔️ QA Passed |
Hi @Nazar65, thank you for your contribution! |
Description (*)
Unfortunately #22081 does in no way fix the real issue in the Sniff, but pushes the problem a few lines down in the code.
The issue is that the
PHP_CodeSniffer\Files\File::findPrevious
method returns either a pointer to the previous token of a type orfalse
if none is found. This case is triggered when the CodeSniffer is running on a file with no closing comment tags.Earlier the issue was because this
false
was passed to a function which expected anint
instead. What #22081 does is to cast the boolean into an integer, which obviously is not correct (as the Sniff now treats the code like there is a comment closing token at position 0 when in fact there is none in the file).Now the Sniff returns a new error as it's trying to get the closing comment from the token list:
Fixed Issues (if relevant)
#20186: Issue title
Manual testing scenarios (*)
./vendor/bin/phpcs --standard=./dev/tests/static/framework/Magento/ Foo.php
Contribution checklist (*)