Skip to content

Commit ece4f5a

Browse files
committed
Introduce a Simple implementation of the TagFactory interface
Less complex interface to implement makes it easier to implement tag factories as they are part of the new behavior of the StandardTagFactory.
1 parent d6c050a commit ece4f5a

File tree

6 files changed

+42
-34
lines changed

6 files changed

+42
-34
lines changed

src/DocBlock/DescriptionFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
*/
4848
class DescriptionFactory
4949
{
50-
/** @var TagFactory */
50+
/** @var SimpleTagFactory */
5151
private $tagFactory;
5252

5353
/**
5454
* Initializes this factory with the means to construct (inline) tags.
5555
*/
56-
public function __construct(TagFactory $tagFactory)
56+
public function __construct(SimpleTagFactory $tagFactory)
5757
{
5858
$this->tagFactory = $tagFactory;
5959
}

src/DocBlock/SimpleTagFactory.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\DocBlock;
15+
16+
use InvalidArgumentException;
17+
use phpDocumentor\Reflection\Types\Context as TypeContext;
18+
19+
interface SimpleTagFactory
20+
{
21+
22+
/**
23+
* Factory method responsible for instantiating the correct sub type.
24+
*
25+
* @param string $tagLine The text for this tag, including description.
26+
*
27+
* @return Tag A new tag object.
28+
*
29+
* @throws InvalidArgumentException If an invalid tag line was presented.
30+
*/
31+
public function create(string $tagLine, ?TypeContext $context = null): Tag;
32+
}

src/DocBlock/StandardTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private function createTag(string $body, string $name, TypeContext $context): Ta
233233
/**
234234
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
235235
*
236-
* @return class-string<Tag>|TagFactory
236+
* @return class-string<Tag>|SimpleTagFactory
237237
*/
238238
private function findHandlerClassName(string $tagName, TypeContext $context)
239239
{
@@ -297,7 +297,7 @@ private function getArgumentsForParametersFromWiring(array $parameters, array $l
297297
* Retrieves a series of ReflectionParameter objects for the static 'create' method of the given
298298
* tag handler class name.
299299
*
300-
* @param class-string|TagFactory $handler
300+
* @param class-string|SimpleTagFactory $handler
301301
*
302302
* @return ReflectionParameter[]
303303
*/

src/DocBlock/TagFactory.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use InvalidArgumentException;
1717
use phpDocumentor\Reflection\Types\Context as TypeContext;
1818

19-
interface TagFactory
19+
interface TagFactory extends SimpleTagFactory
2020
{
2121
/**
2222
* Adds a parameter to the service locator that can be injected in a tag's factory method.
@@ -40,17 +40,6 @@ interface TagFactory
4040
*/
4141
public function addParameter(string $name, $value): void;
4242

43-
/**
44-
* Factory method responsible for instantiating the correct sub type.
45-
*
46-
* @param string $tagLine The text for this tag, including description.
47-
*
48-
* @return Tag A new tag object.
49-
*
50-
* @throws InvalidArgumentException If an invalid tag line was presented.
51-
*/
52-
public function create(string $tagLine, ?TypeContext $context = null): Tag;
53-
5443
/**
5544
* Registers a service with the Service Locator using the FQCN of the class or the alias, if provided.
5645
*

src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
1515

16+
use phpDocumentor\Reflection\DocBlock\SimpleTagFactory;
1617
use phpDocumentor\Reflection\DocBlock\Tag;
1718
use phpDocumentor\Reflection\DocBlock\TagFactory;
1819
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
@@ -31,7 +32,7 @@
3132
*
3233
* @internal This class is not part of the BC promise of this library.
3334
*/
34-
class AbstractPHPStanFactory implements TagFactory
35+
class AbstractPHPStanFactory implements SimpleTagFactory
3536
{
3637
private PhpDocParser $parser;
3738
private Lexer $lexer;
@@ -45,11 +46,6 @@ public function __construct(PHPStanFactory ...$factories)
4546
$this->factories = $factories;
4647
}
4748

48-
public function addParameter(string $name, $value): void
49-
{
50-
// TODO: Implement addParameter() method.
51-
}
52-
5349
public function create(string $tagLine, ?TypeContext $context = null): Tag
5450
{
5551
$tokens = $this->lexer->tokenize($tagLine);
@@ -66,14 +62,4 @@ public function create(string $tagLine, ?TypeContext $context = null): Tag
6662
(string) $ast->value
6763
);
6864
}
69-
70-
public function addService(object $service): void
71-
{
72-
// TODO: Implement addService() method.
73-
}
74-
75-
public function registerTagHandler(string $tagName, string $handler): void
76-
{
77-
// TODO: Implement registerTagHandler() method.
78-
}
7965
}

src/DocBlockFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use InvalidArgumentException;
1717
use LogicException;
1818
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
19+
use phpDocumentor\Reflection\DocBlock\SimpleTagFactory;
1920
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
2021
use phpDocumentor\Reflection\DocBlock\Tag;
2122
use phpDocumentor\Reflection\DocBlock\TagFactory;
@@ -41,13 +42,13 @@ final class DocBlockFactory implements DocBlockFactoryInterface
4142
/** @var DocBlock\DescriptionFactory */
4243
private $descriptionFactory;
4344

44-
/** @var DocBlock\TagFactory */
45+
/** @var DocBlock\SimpleTagFactory */
4546
private $tagFactory;
4647

4748
/**
4849
* Initializes this factory with the required subcontractors.
4950
*/
50-
public function __construct(DescriptionFactory $descriptionFactory, TagFactory $tagFactory)
51+
public function __construct(DescriptionFactory $descriptionFactory, SimpleTagFactory $tagFactory)
5152
{
5253
$this->descriptionFactory = $descriptionFactory;
5354
$this->tagFactory = $tagFactory;

0 commit comments

Comments
 (0)