Skip to content

Commit

Permalink
Merge 03b5215 into 1955c32
Browse files Browse the repository at this point in the history
  • Loading branch information
nightlinus committed Mar 24, 2020
2 parents 1955c32 + 03b5215 commit bfea0a2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
use function array_values;
use function count;
use function lcfirst;
use function max;
use function sprintf;
use function strtolower;
use const T_CLOSURE;
use const T_DOC_COMMENT_CLOSE_TAG;
use const T_DOC_COMMENT_OPEN_TAG;
use const T_DOC_COMMENT_STAR;
use const T_FUNCTION;

Expand Down Expand Up @@ -394,8 +396,11 @@ private function checkFunctionUselessAnnotation(
return;
}

$star = TokenHelper::findPrevious($phpcsFile, T_DOC_COMMENT_STAR, $returnAnnotation->getStartPointer() - 1);
$commentOpen = TokenHelper::findPrevious($phpcsFile, T_DOC_COMMENT_OPEN_TAG, $returnAnnotation->getStartPointer() - 1) + 1;
/** @var int $changeStart */
$changeStart = TokenHelper::findPrevious($phpcsFile, T_DOC_COMMENT_STAR, $returnAnnotation->getStartPointer() - 1);
$changeStart = max($star, $commentOpen);

/** @var int $changeEnd */
$changeEnd = TokenHelper::findNext($phpcsFile, [T_DOC_COMMENT_CLOSE_TAG, T_DOC_COMMENT_STAR], $returnAnnotation->getEndPointer() + 1) - 1;
$phpcsFile->fixer->beginChangeset();
Expand Down
2 changes: 1 addition & 1 deletion tests/Sniffs/TypeHints/ReturnTypeHintSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testErrors(): void
'traversableTypeHints' => ['Traversable'],
]);

self::assertSame(31, $report->getErrorCount());
self::assertSame(32, $report->getErrorCount());

self::assertSniffError($report, 6, ReturnTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT);
self::assertSniffError($report, 14, ReturnTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT);
Expand Down
13 changes: 13 additions & 0 deletions tests/Sniffs/TypeHints/data/returnTypeHintErrors.fixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,17 @@ public function traversableArray(): array
{
}

/**
*
* Documentation
*
*/
public function withComment(): void
{
}

/***/
public function inlinePhpDoc(): string
{
}
}
13 changes: 13 additions & 0 deletions tests/Sniffs/TypeHints/data/returnTypeHintErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,17 @@ public function traversableArray()
{
}

/**
*
* Documentation
*
*/
public function withComment(): void
{
}

/** @return string */
public function inlinePhpDoc(): string
{
}
}

0 comments on commit bfea0a2

Please sign in to comment.