mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
fix docs space test
This commit is contained in:
parent
1585cec922
commit
99f15621be
@ -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",
|
||||
|
@ -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'] ?? '';
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
@ -0,0 +1,3 @@
|
||||
/**
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/
|
||||
*/
|
@ -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
|
||||
|
@ -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
|
||||
{
|
||||
|
||||
}
|
@ -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
|
||||
{
|
||||
|
||||
}
|
@ -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")
|
||||
*/
|
@ -0,0 +1,3 @@
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
@ -0,0 +1,3 @@
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user