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.
This commit is contained in:
Jaapio
2022-10-28 14:37:01 +02:00
parent d6c050a533
commit ece4f5ab18
6 changed files with 42 additions and 34 deletions
+2 -2
View File
@@ -47,13 +47,13 @@ use const PREG_SPLIT_DELIM_CAPTURE;
*/
class DescriptionFactory
{
/** @var TagFactory */
/** @var SimpleTagFactory */
private $tagFactory;
/**
* Initializes this factory with the means to construct (inline) tags.
*/
public function __construct(TagFactory $tagFactory)
public function __construct(SimpleTagFactory $tagFactory)
{
$this->tagFactory = $tagFactory;
}
+32
View File
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock;
use InvalidArgumentException;
use phpDocumentor\Reflection\Types\Context as TypeContext;
interface SimpleTagFactory
{
/**
* Factory method responsible for instantiating the correct sub type.
*
* @param string $tagLine The text for this tag, including description.
*
* @return Tag A new tag object.
*
* @throws InvalidArgumentException If an invalid tag line was presented.
*/
public function create(string $tagLine, ?TypeContext $context = null): Tag;
}
+2 -2
View File
@@ -233,7 +233,7 @@ final class StandardTagFactory implements TagFactory
/**
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
*
* @return class-string<Tag>|TagFactory
* @return class-string<Tag>|SimpleTagFactory
*/
private function findHandlerClassName(string $tagName, TypeContext $context)
{
@@ -297,7 +297,7 @@ final class StandardTagFactory implements TagFactory
* Retrieves a series of ReflectionParameter objects for the static 'create' method of the given
* tag handler class name.
*
* @param class-string|TagFactory $handler
* @param class-string|SimpleTagFactory $handler
*
* @return ReflectionParameter[]
*/
+1 -12
View File
@@ -16,7 +16,7 @@ namespace phpDocumentor\Reflection\DocBlock;
use InvalidArgumentException;
use phpDocumentor\Reflection\Types\Context as TypeContext;
interface TagFactory
interface TagFactory extends SimpleTagFactory
{
/**
* Adds a parameter to the service locator that can be injected in a tag's factory method.
@@ -40,17 +40,6 @@ interface TagFactory
*/
public function addParameter(string $name, $value): void;
/**
* Factory method responsible for instantiating the correct sub type.
*
* @param string $tagLine The text for this tag, including description.
*
* @return Tag A new tag object.
*
* @throws InvalidArgumentException If an invalid tag line was presented.
*/
public function create(string $tagLine, ?TypeContext $context = null): Tag;
/**
* Registers a service with the Service Locator using the FQCN of the class or the alias, if provided.
*
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
use phpDocumentor\Reflection\DocBlock\SimpleTagFactory;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\TagFactory;
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
@@ -31,7 +32,7 @@ use PHPStan\PhpDocParser\Parser\TypeParser;
*
* @internal This class is not part of the BC promise of this library.
*/
class AbstractPHPStanFactory implements TagFactory
class AbstractPHPStanFactory implements SimpleTagFactory
{
private PhpDocParser $parser;
private Lexer $lexer;
@@ -45,11 +46,6 @@ class AbstractPHPStanFactory implements TagFactory
$this->factories = $factories;
}
public function addParameter(string $name, $value): void
{
// TODO: Implement addParameter() method.
}
public function create(string $tagLine, ?TypeContext $context = null): Tag
{
$tokens = $this->lexer->tokenize($tagLine);
@@ -66,14 +62,4 @@ class AbstractPHPStanFactory implements TagFactory
(string) $ast->value
);
}
public function addService(object $service): void
{
// TODO: Implement addService() method.
}
public function registerTagHandler(string $tagName, string $handler): void
{
// TODO: Implement registerTagHandler() method.
}
}