fix docs space test

This commit is contained in:
TomasVotruba 2020-02-25 01:06:18 +01:00
parent 1585cec922
commit 99f15621be
11 changed files with 68 additions and 12 deletions

View File

@ -208,6 +208,7 @@
"rules/cakephp-to-symfony/tests/Rector/Class_/CakePHPModelToDoctrineEntityRector/Source"
],
"files": [
"packages/better-php-doc-parser/tests/PhpDocInfo/PhpDocInfoPrinter/AbstractPhpDocInfoPrinterTest.php",
"rules/dead-code/tests/Rector/MethodCall/RemoveDefaultArgumentValueRector/Source/UserDefined.php",
"rules/type-declaration/tests/Rector/Property/CompleteVarDocTypePropertyRector/Source/EventDispatcher.php",
"rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Source/MyBar.php",

View File

@ -245,8 +245,11 @@ final class PhpDocInfoPrinter
): string {
$output .= $phpDocTagNode->name;
$nodeOutput = $this->printNode($phpDocTagNode->value, $startEndValueObject);
if ($nodeOutput && $this->isTagSeparatedBySpace($nodeOutput, $phpDocTagNode)) {
$output .= ' ';
$tagSpaceSeparator = $this->resolveTagSpaceSeparator($phpDocTagNode);
if ($nodeOutput && $tagSpaceSeparator !== '') {
$output .= $tagSpaceSeparator;
}
if ($phpDocTagNode->getAttribute(Attribute::HAS_DESCRIPTION_WITH_ORIGINAL_SPACES) && (property_exists(
@ -327,13 +330,13 @@ final class PhpDocInfoPrinter
* - "@Route("/", name="homepage")",
* - "@customAnnotation(value)"
*/
private function isTagSeparatedBySpace(string $nodeOutput, PhpDocTagNode $phpDocTagNode): bool
private function resolveTagSpaceSeparator(PhpDocTagNode $phpDocTagNode): string
{
$contentWithoutSpace = $phpDocTagNode->name . Strings::substring($nodeOutput, 0, 1);
if (Strings::contains($this->phpDocInfo->getOriginalContent(), $contentWithoutSpace)) {
return false;
}
$originalContent = $this->phpDocInfo->getOriginalContent();
return Strings::contains($this->phpDocInfo->getOriginalContent(), $phpDocTagNode->name . ' ');
$spacePattern = '#' . preg_quote($phpDocTagNode->name, '#') . '(?<space>\s+)#';
$matches = Strings::match($originalContent, $spacePattern);
return $matches['space'] ?? '';
}
}

View File

@ -0,0 +1,11 @@
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

View File

@ -0,0 +1,3 @@
/**
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/
*/

View File

@ -8,8 +8,6 @@ use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(readOnly=true, repositoryClass="Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Source\ExistingRepositoryClass")
* @ORM\Entity
* @ORM\Entity()
* @ORM\Table(name="answer")
*/
final class SomeEntity

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Fixture;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
final class SomeEntityBrackets
{
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Fixture;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
final class SomeEntitySimple
{
}

View File

@ -1,6 +1,4 @@
/**
* @ORM\Entity(readOnly=true, repositoryClass="Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\Source\ExistingRepositoryClass")
* @ORM\Entity
* @ORM\Entity()
* @ORM\Table(name="answer")
*/

View File

@ -26,6 +26,12 @@ final class ParserClassTest extends AbstractPhpDocInfoTest
{
yield [__DIR__ . '/Fixture/SomeEntity.php', __DIR__ . '/Fixture/expected_some_entity.txt', Class_::class];
yield [
__DIR__ . '/Fixture/SomeEntitySimple.php',
__DIR__ . '/Fixture/expected_some_entity_simple.txt',
Class_::class,
];
yield [
__DIR__ . '/Fixture/SkipNonDoctrineEntity.php',
__DIR__ . '/Fixture/expected_skip_non_doctrine_entity.txt',