Skip to content

Commit

Permalink
DocCommentSpacingSniff: Fixed fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Sep 24, 2018
1 parent 5d77d35 commit 34304e3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,20 @@ private function checkAnnotationsGroupsOrder(
}
}

$endOfLineBeforeFirstAnnotation = TokenHelper::findPreviousContent($phpcsFile, T_DOC_COMMENT_WHITESPACE, $phpcsFile->eolChar, $firstAnnotation->getStartPointer() - 1);
$endOfLineBeforeFirstAnnotation = TokenHelper::findPreviousContent($phpcsFile, T_DOC_COMMENT_WHITESPACE, $phpcsFile->eolChar, $firstAnnotation->getStartPointer() - 1, $docCommentOpenerPointer);
$endOfLineAfterLastAnnotation = TokenHelper::findNextContent($phpcsFile, T_DOC_COMMENT_WHITESPACE, $phpcsFile->eolChar, $lastAnnotation->getEndPointer() + 1);

$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken($endOfLineBeforeFirstAnnotation + 1, $fixedAnnotations);
for ($i = $endOfLineBeforeFirstAnnotation + 2; $i <= $endOfLineAfterLastAnnotation; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
if ($endOfLineBeforeFirstAnnotation === null) {
$phpcsFile->fixer->replaceToken($docCommentOpenerPointer, '/**' . $phpcsFile->eolChar . $fixedAnnotations);
for ($i = $docCommentOpenerPointer + 1; $i <= $endOfLineAfterLastAnnotation; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}
} else {
$phpcsFile->fixer->replaceToken($endOfLineBeforeFirstAnnotation + 1, $fixedAnnotations);
for ($i = $endOfLineBeforeFirstAnnotation + 2; $i <= $endOfLineAfterLastAnnotation; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}
}
$phpcsFile->fixer->endChangeset();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ public function testAnnotationsGroupsErrors(): void
DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP,
]);

self::assertSame(5, $report->getErrorCount());
self::assertSame(6, $report->getErrorCount());

self::assertSniffError($report, 20, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
self::assertSniffError($report, 34, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ANNOTATIONS_GROUPS);
self::assertSniffError($report, 46, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
self::assertSniffError($report, 49, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP);
self::assertSniffError($report, 62, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
self::assertSniffError($report, 83, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);

self::assertAllFixedInFile($report);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,24 @@ public function oneMoreMethod($a, $b, $c)

}

/**
* @return bool
*
* @param int $a
*/
public function methodBeforeInvalidDocComment($a): bool
{

}

/**
* @param int $a
*
* @return bool
*/
public function methodWithInvalidDocComment($a): bool
{

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,22 @@ public function oneMoreMethod($a, $b, $c)

}

/**
* @return bool
*
* @param int $a
*/
public function methodBeforeInvalidDocComment($a): bool
{

}

/** @return bool
* @param int $a
*/
public function methodWithInvalidDocComment($a): bool
{

}

}

0 comments on commit 34304e3

Please sign in to comment.