Skip to content

Commit

Permalink
PhpdocAnnotationWithoutDotFixer - Handle empty line in comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Aug 10, 2018
1 parent 76238aa commit 14190a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php
Expand Up @@ -78,8 +78,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$content = $annotation->getContent();

if (
1 !== Preg::match('/[.。]\h*$/u', $content)
|| 0 !== Preg::match('/[.。](?!\h*$)/u', $content, $matches)
1 !== Preg::match('/[.。]\h*(\R|$)/u', $content)
|| 0 !== Preg::match('/[.。](?!\h*(\R|$))/u', $content, $matches)
) {
continue;
}
Expand All @@ -92,9 +92,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
? sprintf('(?:%s\s+(?:\$\w+\s+)?)?', preg_quote(implode('|', $annotation->getTypes()), '/'))
: '';
$content = Preg::replaceCallback(
'/^(\s*\*\s*@\w+\s+'.$optionalTypeRegEx.')(\p{Lu}?(?=\p{Ll}|\p{Zs}))(.*)$/',
'/^(\s*\*\s*@\w+\s+'.$optionalTypeRegEx.')(\p{Lu}?(?=\p{Ll}|\p{Zs}))(.*)(\R|$)/',
static function (array $matches) {
return $matches[1].strtolower($matches[2]).$matches[3];
return $matches[1].strtolower($matches[2]).$matches[3].$matches[4];
},
$startLine->getContent(),
1
Expand Down
30 changes: 30 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php
Expand Up @@ -159,6 +159,36 @@ public function provideFixCases()
* @throws \Exception having tabs after dot, yet I am fixed. '.'
*/',
],
[
'<?php
/**
* This is a broken phpdoc
* @param string $str surprisingly, it is a string
*/
function fixMe($str) {}',
'<?php
/**
* This is a broken phpdoc
* @param string $str Surprisingly, it is a string.
*/
function fixMe($str) {}',
],
[
'<?php
/**
* @return bool|null returns `true` if the class has a single-column ID
Returns `false` otherwise.
*/
function fixMe() {}',
'<?php
/**
* @return bool|null Returns `true` if the class has a single-column ID.
Returns `false` otherwise.
*/
function fixMe() {}',
],
];
}
}

0 comments on commit 14190a4

Please sign in to comment.