cleanup extra space in doc print

This commit is contained in:
TomasVotruba 2020-02-29 02:01:58 +01:00
parent 3125cc38c8
commit 13dff989c9
4 changed files with 20 additions and 0 deletions

View File

@ -102,6 +102,9 @@ final class PhpDocInfoPrinter
$phpDocString = $this->printPhpDocNode($this->attributeAwarePhpDocNode);
// replace extra space after *
$phpDocString = Strings::replace($phpDocString, '#([^*])\*[ \t]+$#sm', '$1*');
// hotfix of extra space with callable ()
return Strings::replace($phpDocString, '#callable(\s+)\(#', 'callable(');
}

View File

@ -0,0 +1,5 @@
/**
* Test.
*
* @param string $param
*/

View File

@ -22,6 +22,18 @@ final class PhpDocInfoPrinterTest extends AbstractPhpDocInfoPrinterTest
$this->assertSame($docComment, $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo));
}
public function testRemoveSpace(): void
{
$docComment = FileSystem::read(__DIR__ . '/FixtureChanged/with_space.txt');
$phpDocInfo = $this->createPhpDocInfoFromDocCommentAndNode($docComment, new Nop());
$expectedDocComment = FileSystem::read(__DIR__ . '/FixtureChanged/with_space_expected.txt.inc');
$printedDocComment = $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo);
$this->assertSame($expectedDocComment, $printedDocComment);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureBasic', '*.txt');