Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ public function readMethodAnnotation(ClassMethod $classMethod, string $annotatio

/** @var object[] $methodAnnotations */
$methodAnnotations = $this->reader->getMethodAnnotations($reflectionMethod);

foreach ($methodAnnotations as $methodAnnotation) {
if (! is_a($methodAnnotation, $annotationClassName, true)) {
continue;
}

$objectHash = md5(spl_object_hash($classMethod) . serialize($methodAnnotation));

if (in_array($objectHash, $this->alreadyProvidedAnnotations, true)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator

return new SymfonyRouteTagValueNode(
$route->getPath(),
method_exists($route, 'getLocalizedPaths') ? $route->getLocalizedPaths() : [],
$this->getLocalizedPaths($route),
$route->getName(),
$route->getMethods(),
$route->getOptions(),
Expand All @@ -49,4 +49,13 @@ public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator
$annotationContent
);
}

private function getLocalizedPaths(Route $route): array
{
if (method_exists($route, 'getLocalizedPaths')) {
return $route->getLocalizedPaths();
}

return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ private function printPhpDocNode(AttributeAwarePhpDocNode $attributeAwarePhpDocN
$output = '/**' . $output;
}

// fix missing end
if (Strings::match($output, '#^(/\*\*)#') && $output && ! Strings::match($output, '#\s\*\/(\s+)?$#')) {
$output .= ' */';
}

return $output;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\CaseSensitive;
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\IndexInTable;
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\Short;
use Symplify\SmartFileSystem\SmartFileInfo;

final class DoctrineTest extends AbstractPhpDocInfoPrinterTest
{
Expand All @@ -22,11 +23,10 @@ public function testClass(string $docFilePath, Node $node): void
$docComment = FileSystem::read($docFilePath);
$phpDocInfo = $this->createPhpDocInfoFromDocCommentAndNode($docComment, $node);

$this->assertSame(
$docComment,
$this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo),
'Caused in ' . $docFilePath
);
$fileInfo = new SmartFileInfo($docFilePath);
$message = $fileInfo->getRelativeFilePathFromCwd();

$this->assertSame($docComment, $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo), $message);
}

public function provideDataClass(): Iterator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\SinglePropertyClass;
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\TableClass;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\SmartFileSystem\SmartFileInfo;

final class MultilineTest extends AbstractPhpDocInfoPrinterTest
{
Expand All @@ -33,7 +34,10 @@ public function test(string $docFilePath, Node $node): void
$docComment = FileSystem::read($docFilePath);
$phpDocInfo = $this->createPhpDocInfoFromDocCommentAndNode($docComment, $node);

$this->assertSame($docComment, $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo));
$fileInfo = new SmartFileInfo($docFilePath);
$message = $fileInfo->getRelativeFilePathFromCwd();

$this->assertSame($docComment, $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo), $message);
}

public function provideData(): Iterator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
* @Orm\Index(name="dateTo_idx", columns={"dateTo"}),
* }
* )
*/
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* @UniqueConstraint(name="content_status_unique", columns={"content_id", "site_id", "lang"})
* }
* )
*/
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
* @Serializer\Type("boolean")
* @var bool
*/
public $anotherProperty;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
* "bool"
* )
*/
public $anotherSerializeSingleLine;
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
* protocols = {"https"}
* )
*/
private $manyTo;
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
* @ORM\JoinColumn(referencedColumnName="id")
* })
*/
protected $someProperty;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\DoctrineColumn;

use Doctrine\ORM\Mapping as ORM;

final class InlinedColumn
{
/** @ORM\Column(name="url", type="string") */
private $loginCount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\SymfonyRoute;

use Symfony\Component\Routing\Annotation\Route;

final class MultiRoute
{
/**
* @Route("/new", name="route_1", methods={"GET", "POST"})
* @Route("/{id}", name="route_2", methods={"GET", "POST"})
*/
public function run()
{
}
}