Skip to content

Commit 9884254

Browse files
committed
phpcs error on rule classes - must be of the type integer
1 parent 211dd25 commit 9884254

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

dev/tests/static/framework/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ public function process(File $phpcsFile, $stackPtr)
9797
{
9898
$tokens = $phpcsFile->getTokens();
9999
$previousCommentClosePtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1, 0);
100-
$this->validateAnnotationBlockExists($phpcsFile, (int)$previousCommentClosePtr, (int)$stackPtr);
101-
$commentStartPtr = (int)$phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, 0);
100+
if (!$previousCommentClosePtr) {
101+
$phpcsFile->addError('Comment block is missing', $stackPtr -1, 'MethodArguments');
102+
return;
103+
}
104+
$this->validateAnnotationBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr);
105+
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, 0);
102106
$commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];
103107
$emptyTypeTokens = [
104108
T_DOC_COMMENT_WHITESPACE,
@@ -111,7 +115,7 @@ public function process(File $phpcsFile, $stackPtr)
111115
} else {
112116
$this->annotationFormatValidator->validateDescriptionFormatStructure(
113117
$phpcsFile,
114-
(int)$commentStartPtr,
118+
$commentStartPtr,
115119
(int) $shortPtr,
116120
$previousCommentClosePtr,
117121
$emptyTypeTokens

dev/tests/static/framework/Magento/Sniffs/Annotation/MethodAnnotationStructureSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function process(File $phpcsFile, $stackPtr)
4545
$tokens = $phpcsFile->getTokens();
4646
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, ($stackPtr), 0);
4747
$commentEndPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr), 0);
48+
if (!$commentStartPtr) {
49+
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
50+
return;
51+
}
4852
$commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];
4953
$functionPtrContent = $tokens[$stackPtr+2]['content'] ;
5054
if (preg_match('/(?i)__construct/', $functionPtrContent)) {

dev/tests/static/framework/Magento/Sniffs/Annotation/MethodArgumentsSniff.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,12 @@ public function process(File $phpcsFile, $stackPtr)
550550
$numTokens = count($tokens);
551551
$previousCommentOpenPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, 0);
552552
$previousCommentClosePtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1, 0);
553-
if (!$this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)) {
554-
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
553+
if ($previousCommentClosePtr && $previousCommentOpenPtr) {
554+
if (!$this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)) {
555+
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
556+
return;
557+
}
558+
} else {
555559
return;
556560
}
557561
$openParenthesisPtr = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1, $numTokens);
@@ -663,6 +667,9 @@ private function noneParamsAligned(array $argumentPositions, array $commentPosit
663667
foreach ($argumentPositions as $index => $argumentPosition) {
664668
$commentPosition = $commentPositions[$index];
665669
$type = $paramDefinitions[$index]['type'];
670+
if ($type === null) {
671+
continue;
672+
}
666673
$paramName = $paramDefinitions[$index]['paramName'];
667674
if (($argumentPosition !== strlen($type) + 1) ||
668675
(isset($commentPosition) && ($commentPosition !== $argumentPosition + strlen($paramName) + 1))) {

0 commit comments

Comments
 (0)