Skip to content

Commit

Permalink
bug #3867 PhpdocAnnotationWithoutDotFixer - Handle trailing whitespac…
Browse files Browse the repository at this point in the history
…es (kubawerlos)

This PR was squashed before being merged into the 2.12 branch (closes #3867).

Discussion
----------

PhpdocAnnotationWithoutDotFixer - Handle trailing whitespaces

Solves #3857 - I guess @SpacePossum will have some more fancy test cases.

Commits
-------

3897460 PhpdocAnnotationWithoutDotFixer - Handle trailing whitespaces
  • Loading branch information
keradus committed Aug 1, 2018
2 parents f75251b + 3897460 commit c342bad
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 c342bad

Please sign in to comment.