Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/DocBlock/Tags/InvalidTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use function is_array;
use function is_object;
use function is_resource;
use function ltrim;
use function sprintf;

use const PHP_VERSION_ID;
Expand Down Expand Up @@ -58,7 +59,9 @@ public function getName(): string

public static function create(string $body, string $name = ''): self
{
return new self($name, $body);
// Some upstream parsers (e.g. phpstan/phpdoc-parser) keep the leading "@" in the tag name they expose.
// All other tags strip it before reaching the Tag layer, so normalize here to keep getName() consistent.
return new self(ltrim($name, '@'), $body);
}

public function withError(Throwable $exception): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testCreateReturnsInvalidTagWhenNoFactorySupports(): void
$result = $sut->create('@unknown string $param');

self::assertInstanceOf(InvalidTag::class, $result);
self::assertEquals('@unknown', $result->getName());
self::assertEquals('unknown', $result->getName());
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/DocBlock/Tags/InvalidTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public function testCreationWithoutError(): void
self::assertNull($tag->getException());
}

public function testCreationStripsLeadingAtFromName(): void
{
$tag = InvalidTag::create('Body', '@var');

self::assertSame('var', $tag->getName());
self::assertSame('@var Body', $tag->render());
}

/**
* @covers ::withError
* @covers ::__toString
Expand Down