Skip to content

Commit

Permalink
PhpdocAnnotationWithoutDotFixer - Handle trailing whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and keradus committed Aug 1, 2018
1 parent 1c9553a commit 3897460
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php
Expand Up @@ -78,14 +78,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$content = $annotation->getContent();

if (
1 !== Preg::match('/[.。]$/u', $content)
|| 0 !== Preg::match('/[.。](?!$)/u', $content, $matches)
1 !== Preg::match('/[.。]\h*$/u', $content)
|| 0 !== Preg::match('/[.。](?!\h*$)/u', $content, $matches)
) {
continue;
}

$endLine = $doc->getLine($annotation->getEnd());
$endLine->setContent(Preg::replace('/(?<![.。])[.。](\s+)$/u', '\1', $endLine->getContent()));
$endLine->setContent(Preg::replace('/(?<![.。])[.。]\h*(\H+)$/u', '\1', $endLine->getContent()));

$startLine = $doc->getLine($annotation->getStart());
$optionalTypeRegEx = $annotation->supportTypes()
Expand Down
20 changes: 20 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php
Expand Up @@ -137,6 +137,26 @@ public function provideFixCases()
/**
* @return bool|null Returns `true` if the class has a single-column ID
* and Returns `false` otherwise.
*/',
],
[
'<?php
/**
* @throws \Exception having whitespaces after dot, yet I am fixed
*/',
'<?php
/**
* @throws \Exception having whitespaces after dot, yet I am fixed. '.'
*/',
],
[
'<?php
/**
* @throws \Exception having tabs after dot, yet I am fixed
*/',
'<?php
/**
* @throws \Exception having tabs after dot, yet I am fixed. '.'
*/',
],
];
Expand Down

0 comments on commit 3897460

Please sign in to comment.