mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
decouple hasDescription() method
This commit is contained in:
parent
53ac8fcc41
commit
24833bb00e
@ -257,10 +257,7 @@ final class PhpDocInfoPrinter
|
||||
$output .= $tagSpaceSeparator;
|
||||
}
|
||||
|
||||
if ($phpDocTagNode->getAttribute(Attribute::HAS_DESCRIPTION_WITH_ORIGINAL_SPACES) && (property_exists(
|
||||
$phpDocTagNode->value,
|
||||
'description'
|
||||
) && $phpDocTagNode->value->description)) {
|
||||
if ($this->hasDescription($phpDocTagNode)) {
|
||||
$quotedDescription = preg_quote($phpDocTagNode->value->description, '#');
|
||||
$pattern = Strings::replace($quotedDescription, '#[\s]+#', '\s+');
|
||||
$nodeOutput = Strings::replace($nodeOutput, '#' . $pattern . '#', $phpDocTagNode->value->description);
|
||||
@ -344,4 +341,12 @@ final class PhpDocInfoPrinter
|
||||
|
||||
return $matches['space'] ?? '';
|
||||
}
|
||||
|
||||
private function hasDescription(PhpDocTagNode $phpDocTagNode): bool
|
||||
{
|
||||
return $phpDocTagNode->getAttribute(Attribute::HAS_DESCRIPTION_WITH_ORIGINAL_SPACES) && (property_exists(
|
||||
$phpDocTagNode->value,
|
||||
'description'
|
||||
) && $phpDocTagNode->value->description);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
/**
|
||||
* @return (string|bool)[]
|
||||
*/
|
@ -16,22 +16,15 @@ final class PhpDocInfoPrinterTest extends AbstractPhpDocInfoPrinterTest
|
||||
*/
|
||||
public function test(string $docFilePath): void
|
||||
{
|
||||
$docComment = FileSystem::read($docFilePath);
|
||||
$phpDocInfo = $this->createPhpDocInfoFromDocCommentAndNode($docComment, new Nop());
|
||||
|
||||
$this->assertSame($docComment, $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo));
|
||||
$this->doComparePrintedFileEquals($docFilePath, $docFilePath);
|
||||
}
|
||||
|
||||
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);
|
||||
$this->doComparePrintedFileEquals(
|
||||
__DIR__ . '/FixtureChanged/with_space.txt',
|
||||
__DIR__ . '/FixtureChanged/with_space_expected.txt.inc'
|
||||
);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
@ -59,4 +52,15 @@ final class PhpDocInfoPrinterTest extends AbstractPhpDocInfoPrinterTest
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureEmpty', '*.txt');
|
||||
}
|
||||
|
||||
private function doComparePrintedFileEquals(string $inputDocFile, string $expectedOutputDocFile): void
|
||||
{
|
||||
$docComment = FileSystem::read($inputDocFile);
|
||||
$phpDocInfo = $this->createPhpDocInfoFromDocCommentAndNode($docComment, new Nop());
|
||||
|
||||
$printedDocComment = $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo);
|
||||
|
||||
$expectedDocComment = FileSystem::read($expectedOutputDocFile);
|
||||
$this->assertSame($expectedDocComment, $printedDocComment);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user