Skip to content

Commit 7efc33c

Browse files
committed
Add more common tag interfaces
1 parent 76a5811 commit 7efc33c

12 files changed

+100
-23
lines changed

src/DocBlock.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
use TypeLang\PHPDoc\Tag\Description;
88
use TypeLang\PHPDoc\Tag\DescriptionInterface;
99
use TypeLang\PHPDoc\Tag\DescriptionProviderInterface;
10+
use TypeLang\PHPDoc\Tag\OptionalDescriptionProviderInterface;
1011
use TypeLang\PHPDoc\Tag\TagInterface;
11-
use TypeLang\PHPDoc\Tag\TagProvider;
12-
use TypeLang\PHPDoc\Tag\TagProviderInterface;
12+
use TypeLang\PHPDoc\Tag\TagsProvider;
13+
use TypeLang\PHPDoc\Tag\TagsProviderInterface;
1314

1415
/**
1516
* This class represents structure containing a description and a set of tags
@@ -19,12 +20,12 @@
1920
* @template-implements \ArrayAccess<int<0, max>, TagInterface|null>
2021
*/
2122
final class DocBlock implements
22-
DescriptionProviderInterface,
23-
TagProviderInterface,
23+
OptionalDescriptionProviderInterface,
24+
TagsProviderInterface,
2425
\IteratorAggregate,
2526
\ArrayAccess
2627
{
27-
use TagProvider;
28+
use TagsProvider;
2829

2930
private readonly DescriptionInterface $description;
3031

src/Tag/Description.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class Description implements DescriptionInterface, \IteratorAggregate
1111
{
12-
use TagProvider;
12+
use TagsProvider;
1313

1414
protected readonly string $template;
1515

src/Tag/DescriptionInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TypeLang\PHPDoc\Tag;
66

7-
interface DescriptionInterface extends TagProviderInterface, \Stringable
7+
interface DescriptionInterface extends TagsProviderInterface, \Stringable
88
{
99
/**
1010
* Returns the body template.

src/Tag/DescriptionProviderInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace TypeLang\PHPDoc\Tag;
66

7-
interface DescriptionProviderInterface
7+
interface DescriptionProviderInterface extends OptionalDescriptionProviderInterface
88
{
99
/**
1010
* Returns description object which can be represented as a string and
1111
* contains additional information.
1212
*
1313
* @psalm-immutable Each call to the method must return the same value.
1414
*/
15-
public function getDescription(): ?DescriptionInterface;
15+
public function getDescription(): DescriptionInterface;
1616
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\Tag;
6+
7+
interface OptionalDescriptionProviderInterface
8+
{
9+
/**
10+
* Returns description object which can be represented as a string and
11+
* contains additional information.
12+
*
13+
* @psalm-immutable Each call to the method must return the same value.
14+
*/
15+
public function getDescription(): ?DescriptionInterface;
16+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\Tag;
6+
7+
use TypeLang\Parser\Node\Stmt\TypeStatement;
8+
9+
/**
10+
* Every class that implements a given interface is an implementation of a
11+
* tag that contains type information (that is, an AST object).
12+
*
13+
* Requires a `type-lang/parser` dependency for {@see TypeStatement} support.
14+
*
15+
* @psalm-suppress UndefinedClass : Expects optional `type-lang/parser` dependency.
16+
*/
17+
interface OptionalTypeProviderInterface
18+
{
19+
/**
20+
* Returns an AST object of the type or {@see null} in case the
21+
* type is not specified.
22+
*
23+
* @psalm-immutable Each call to the method must return the same value.
24+
*/
25+
public function getType(): ?TypeStatement;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\Tag;
6+
7+
interface OptionalVariableNameProviderInterface
8+
{
9+
/**
10+
* Returns the name of the variable (parameter, field, etc.) to
11+
* which this tag is attached or {@see null} in case of the tag does
12+
* not contain a name.
13+
*
14+
* @psalm-immutable Each call to the method must return the same value.
15+
*
16+
* @return non-empty-string|null
17+
*/
18+
public function getVariable(): ?string;
19+
}

src/Tag/TagInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TypeLang\PHPDoc\Tag;
66

7-
interface TagInterface extends DescriptionProviderInterface, \Stringable
7+
interface TagInterface extends OptionalDescriptionProviderInterface, \Stringable
88
{
99
/**
1010
* Returns the non-empty tag name string without the '@' prefix.

src/Tag/TagProvider.php renamed to src/Tag/TagsProvider.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
namespace TypeLang\PHPDoc\Tag;
66

77
/**
8-
* @mixin TagProviderInterface
8+
* @mixin TagsProviderInterface
99
* @mixin \IteratorAggregate
1010
*
11-
* @psalm-require-implements TagProviderInterface
11+
* @psalm-require-implements TagsProviderInterface
1212
* @psalm-require-implements \IteratorAggregate
1313
*
1414
* @internal This is an internal library trait, please do not use it in your code.
1515
* @psalm-internal TypeLang\PHPDoc\Tag
1616
*/
17-
trait TagProvider
17+
trait TagsProvider
1818
{
1919
/**
2020
* @var list<TagInterface>
@@ -32,9 +32,9 @@ protected function bootTagProvider(iterable $tags): void
3232
}
3333

3434
/**
35-
* @see TagProviderInterface::getTags()
36-
*
3735
* @return list<TagInterface>
36+
*@see TagsProviderInterface::getTags()
37+
*
3838
*/
3939
public function getTags(): array
4040
{
@@ -51,7 +51,7 @@ public function getIterator(): \Traversable
5151

5252
$description = $tag->getDescription();
5353

54-
if ($description instanceof TagProviderInterface) {
54+
if ($description instanceof TagsProviderInterface) {
5555
yield from $description;
5656
}
5757
}

src/Tag/TagProviderInterface.php renamed to src/Tag/TagsProviderInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @internal This is an internal library interface, please do not use it in your code.
1111
* @psalm-internal TypeLang\PHPDoc\Tag
1212
*/
13-
interface TagProviderInterface extends \Traversable, \Countable
13+
interface TagsProviderInterface extends \Traversable, \Countable
1414
{
1515
/**
1616
* Returns the tags for this object.

src/Tag/TypeProviderInterface.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
use TypeLang\Parser\Node\Stmt\TypeStatement;
88

99
/**
10-
* Every class that implements a given interface is an implementation of a
11-
* tag that contains type information (that is, an AST object).
12-
*
13-
* Requires a `type-lang/parser` dependency for {@see TypeStatement} support.
14-
*
1510
* @psalm-suppress UndefinedClass : Expects optional `type-lang/parser` dependency.
1611
*/
17-
interface TypeProviderInterface
12+
interface TypeProviderInterface extends OptionalTypeProviderInterface
1813
{
1914
/**
2015
* Returns an AST object of the type.
16+
*
17+
* @psalm-immutable Each call to the method must return the same value.
2118
*/
2219
public function getType(): TypeStatement;
2320
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\Tag;
6+
7+
interface VariableNameProviderInterface extends OptionalVariableNameProviderInterface
8+
{
9+
/**
10+
* Returns the name of the variable (parameter, field, etc.) to
11+
* which this tag is attached.
12+
*
13+
* @psalm-immutable Each call to the method must return the same value.
14+
*
15+
* @return non-empty-string
16+
*/
17+
public function getVariable(): string;
18+
}

0 commit comments

Comments
 (0)