Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpdocAnnotationWithoutDotFixer - Handle empty line in comment #3882

Merged
merged 1 commit into from Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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() {}',
],
];
}
}