Skip to content

Commit a96764e

Browse files
committed
Sort imports, relocate Author static methods, add negative hint test
1 parent c565aa9 commit a96764e

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/DocBlock/StandardTagFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use phpDocumentor\Reflection\DocBlock\Tags\Author;
1818
use phpDocumentor\Reflection\DocBlock\Tags\Covers;
1919
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
20+
use phpDocumentor\Reflection\DocBlock\Tags\ExpectedFormat;
2021
use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory;
2122
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ExtendsFactory;
2223
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
@@ -32,7 +33,6 @@
3233
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateFactory;
3334
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ThrowsFactory;
3435
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
35-
use phpDocumentor\Reflection\DocBlock\Tags\ExpectedFormat;
3636
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
3737
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
3838
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;

src/DocBlock/Tags/Author.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ final class Author extends BaseTag implements ExpectedFormat
2929
/** @var string register that this is the author tag. */
3030
protected string $name = 'author';
3131

32-
public static function getExpectedFormat(): string
33-
{
34-
return 'name [<email@example.com>]';
35-
}
36-
37-
public static function getDocumentationUrl(): ?string
38-
{
39-
return 'https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/author.html';
40-
}
41-
4232
/** @var string The name of the author */
4333
private string $authorName;
4434

@@ -109,4 +99,14 @@ public static function create(string $body): ?self
10999

110100
return new static($authorName, $email);
111101
}
102+
103+
public static function getExpectedFormat(): string
104+
{
105+
return 'name [<email@example.com>]';
106+
}
107+
108+
public static function getDocumentationUrl(): ?string
109+
{
110+
return 'https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/author.html';
111+
}
112112
}

tests/unit/DocBlock/StandardTagFactoryTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
use phpDocumentor\Reflection\Assets\CustomServiceInterface;
2222
use phpDocumentor\Reflection\Assets\CustomTagFactory;
2323
use phpDocumentor\Reflection\DocBlock\Tags\Author;
24-
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
2524
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
2625
use phpDocumentor\Reflection\DocBlock\Tags\Extends_;
2726
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
2827
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
2928
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
3029
use phpDocumentor\Reflection\DocBlock\Tags\Implements_;
30+
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
3131
use phpDocumentor\Reflection\DocBlock\Tags\Method;
3232
use phpDocumentor\Reflection\DocBlock\Tags\Mixin;
3333
use phpDocumentor\Reflection\DocBlock\Tags\Param;
@@ -158,6 +158,30 @@ public function testInvalidTagReceivesFormatHintFromHandler(): void
158158
$this->assertSame(Author::getDocumentationUrl(), $tag->getDocumentationUrl());
159159
}
160160

161+
/**
162+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
163+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
164+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
165+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\InvalidTag
166+
*
167+
* @covers ::__construct
168+
* @covers ::create
169+
*/
170+
public function testInvalidTagKeepsNullHintsWhenHandlerDoesNotAdvertiseAny(): void
171+
{
172+
$context = new Context('');
173+
$descriptionFactory = m::mock(DescriptionFactory::class);
174+
$descriptionFactory->shouldReceive('create')->andThrow(new InvalidArgumentException('boom'));
175+
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));
176+
$tagFactory->addService($descriptionFactory, DescriptionFactory::class);
177+
178+
$tag = $tagFactory->create('@custom anything', $context);
179+
180+
$this->assertInstanceOf(InvalidTag::class, $tag);
181+
$this->assertNull($tag->getExpectedFormat());
182+
$this->assertNull($tag->getDocumentationUrl());
183+
}
184+
161185
/**
162186
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
163187
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See

0 commit comments

Comments
 (0)