Skip to content

Commit 1fe2653

Browse files
committed
Improve tags logic and add "@var" and "@param" tests
1 parent be887d2 commit 1fe2653

38 files changed

+807
-294
lines changed

Diff for: composer.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"php": "^8.1",
1313
"type-lang/parser": "^1.4"
1414
},
15+
"replace": {
16+
"type-lang/phpdoc-standard-tags": "*",
17+
"type-lang/phpdoc-template-tags": "*"
18+
},
1519
"autoload": {
1620
"psr-4": {
1721
"TypeLang\\PHPDoc\\": "src"
@@ -25,6 +29,7 @@
2529
"phpstan/phpstan": "^2.1",
2630
"phpstan/phpstan-strict-rules": "^2.0",
2731
"phpunit/phpunit": "^10.5|^11.0|^12.0",
32+
"symfony/property-access": "^5.4|^6.0|^7.0",
2833
"symfony/var-dumper": "^5.4|^6.0|^7.0"
2934
},
3035
"autoload-dev": {
@@ -34,8 +39,8 @@
3439
},
3540
"extra": {
3641
"branch-alias": {
37-
"dev-master": "1.x-dev",
38-
"dev-main": "1.x-dev"
42+
"dev-master": "2.x-dev",
43+
"dev-main": "2.x-dev"
3944
}
4045
},
4146
"config": {
@@ -53,7 +58,7 @@
5358
"@test:functional"
5459
],
5560
"test:unit": "phpunit --testdox --testsuite=unit",
56-
"test:functional": "phpunit --testsuite=functional",
61+
"test:functional": "phpunit --testdox --testsuite=functional",
5762
"linter": "@linter:check",
5863
"linter:check": "phpstan analyse --configuration phpstan.neon",
5964
"linter:baseline": "phpstan analyse --configuration phpstan.neon --generate-baseline",

Diff for: src/DocBlock/DocBlock.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@
66

77
use TypeLang\PHPDoc\DocBlock\Description\Description;
88
use TypeLang\PHPDoc\DocBlock\Description\DescriptionInterface;
9+
use TypeLang\PHPDoc\DocBlock\Description\OptionalDescriptionProviderInterface;
910
use TypeLang\PHPDoc\DocBlock\Tag\TagInterface;
11+
use TypeLang\PHPDoc\DocBlock\Tag\TagsProviderInterface;
1012

1113
/**
14+
* An implementation represents structure containing a description and a set
15+
* of tags that describe an arbitrary DocBlock Comment in the code.
16+
*
1217
* @template-implements \ArrayAccess<array-key, TagInterface|null>
1318
* @template-implements \IteratorAggregate<array-key, TagInterface>
1419
*/
1520
final class DocBlock implements
16-
DocBlockInterface,
21+
OptionalDescriptionProviderInterface,
22+
TagsProviderInterface,
1723
\IteratorAggregate,
18-
\ArrayAccess
24+
\ArrayAccess,
25+
\Countable
1926
{
2027
public readonly ?DescriptionInterface $description;
2128

Diff for: src/DocBlock/DocBlockInterface.php

-21
This file was deleted.

Diff for: src/DocBlock/Tag/Factory/TagFactory.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ public function create(string $tag, string $content, DescriptionParserInterface
5555
);
5656
}
5757
} catch (RuntimeExceptionInterface $e) {
58-
return new InvalidTag(
59-
reason: $e,
60-
description: $descriptions->parse($content),
61-
name: $tag,
62-
);
58+
$description = null;
59+
60+
if ($content !== '') {
61+
$description = $descriptions->parse($content);
62+
}
63+
64+
return new InvalidTag($tag, $e, $description);
6365
}
6466
}
6567

Diff for: src/DocBlock/Tag/InvalidTag.php

+3-16
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,21 @@
44

55
namespace TypeLang\PHPDoc\DocBlock\Tag;
66

7-
final class InvalidTag extends Tag implements InvalidTagInterface
7+
class InvalidTag extends Tag implements InvalidTagInterface
88
{
9-
/**
10-
* @var non-empty-string
11-
*/
12-
public const DEFAULT_UNKNOWN_TAG_NAME = 'invalid';
13-
14-
private readonly bool $isUnknownName;
15-
169
/**
1710
* @param non-empty-string $name
1811
*/
1912
public function __construct(
13+
string $name,
2014
public readonly \Throwable $reason,
2115
\Stringable|string|null $description = null,
22-
?string $name = null,
2316
) {
24-
$this->isUnknownName = $name === null;
25-
26-
parent::__construct($name ?? self::DEFAULT_UNKNOWN_TAG_NAME, $description);
17+
parent::__construct($name, $description);
2718
}
2819

2920
public function __toString(): string
3021
{
31-
if ($this->isUnknownName) {
32-
return \sprintf('@%s', $this->description);
33-
}
34-
3522
if ($this->description === null) {
3623
return \sprintf('@%s', $this->name);
3724
}

Diff for: src/DocBlock/Tag/MethodTag/MethodTagFactory.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
use TypeLang\Parser\Node\Stmt\CallableTypeNode;
88
use TypeLang\Parser\Parser as TypesParser;
99
use TypeLang\Parser\ParserInterface as TypesParserInterface;
10-
use TypeLang\PHPDoc\DocBlock\Content\OptionalTypeParserReader;
11-
use TypeLang\PHPDoc\DocBlock\Content\OptionalValueReader;
12-
use TypeLang\PHPDoc\DocBlock\Content\Stream;
13-
use TypeLang\PHPDoc\DocBlock\Content\TypeParserReader;
1410
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
11+
use TypeLang\PHPDoc\Parser\Content\OptionalTypeParserReader;
12+
use TypeLang\PHPDoc\Parser\Content\OptionalValueReader;
13+
use TypeLang\PHPDoc\Parser\Content\Stream;
14+
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
1515
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1616

1717
/**

Diff for: src/DocBlock/Tag/ParamTag/ParamTagFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use TypeLang\Parser\Parser as TypesParser;
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
9-
use TypeLang\PHPDoc\DocBlock\Content\Stream;
10-
use TypeLang\PHPDoc\DocBlock\Content\TypeParserReader;
11-
use TypeLang\PHPDoc\DocBlock\Content\VariableNameReader;
129
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
10+
use TypeLang\PHPDoc\Parser\Content\Stream;
11+
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
12+
use TypeLang\PHPDoc\Parser\Content\VariableNameReader;
1313
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1414

1515
/**

Diff for: src/DocBlock/Tag/PropertyTag/PropertyTagFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use TypeLang\Parser\Parser as TypesParser;
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
9-
use TypeLang\PHPDoc\DocBlock\Content\Stream;
10-
use TypeLang\PHPDoc\DocBlock\Content\TypeParserReader;
11-
use TypeLang\PHPDoc\DocBlock\Content\VariableNameReader;
129
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
10+
use TypeLang\PHPDoc\Parser\Content\Stream;
11+
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
12+
use TypeLang\PHPDoc\Parser\Content\VariableNameReader;
1313
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1414

1515
/**

Diff for: src/DocBlock/Tag/ReturnTag/ReturnTagFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use TypeLang\Parser\Parser as TypesParser;
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
9-
use TypeLang\PHPDoc\DocBlock\Content\Stream;
10-
use TypeLang\PHPDoc\DocBlock\Content\TypeParserReader;
119
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
10+
use TypeLang\PHPDoc\Parser\Content\Stream;
11+
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
1212
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1313

1414
/**

Diff for: src/DocBlock/Tag/TemplateExtendsTag/TemplateExtendsTagFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use TypeLang\Parser\Parser as TypesParser;
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
9-
use TypeLang\PHPDoc\DocBlock\Content\Stream;
10-
use TypeLang\PHPDoc\DocBlock\Content\TypeParserReader;
119
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
10+
use TypeLang\PHPDoc\Parser\Content\Stream;
11+
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
1212
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1313

1414
/**

Diff for: src/DocBlock/Tag/TemplateTag/TemplateTagFactory.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
use TypeLang\Parser\Parser as TypesParser;
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
9-
use TypeLang\PHPDoc\DocBlock\Content\IdentifierReader;
10-
use TypeLang\PHPDoc\DocBlock\Content\OptionalTypeParserReader;
11-
use TypeLang\PHPDoc\DocBlock\Content\OptionalValueReader;
12-
use TypeLang\PHPDoc\DocBlock\Content\Stream;
139
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
10+
use TypeLang\PHPDoc\Parser\Content\IdentifierReader;
11+
use TypeLang\PHPDoc\Parser\Content\OptionalTypeParserReader;
12+
use TypeLang\PHPDoc\Parser\Content\OptionalValueReader;
13+
use TypeLang\PHPDoc\Parser\Content\Stream;
1414
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1515

1616
/**

Diff for: src/DocBlock/Tag/ThrowsTag/ThrowsTagFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use TypeLang\Parser\Parser as TypesParser;
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
9-
use TypeLang\PHPDoc\DocBlock\Content\Stream;
10-
use TypeLang\PHPDoc\DocBlock\Content\TypeParserReader;
119
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
10+
use TypeLang\PHPDoc\Parser\Content\Stream;
11+
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
1212
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1313

1414
/**

Diff for: src/DocBlock/Tag/UnknownTag.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\DocBlock\Tag;
6+
7+
class UnknownTag extends Tag implements InvalidTagInterface
8+
{
9+
/**
10+
* @var non-empty-string
11+
*/
12+
public const DEFAULT_UNKNOWN_TAG_NAME = 'unknown';
13+
14+
public function __construct(
15+
public readonly \Throwable $reason,
16+
\Stringable|string|null $description = null,
17+
) {
18+
parent::__construct(self::DEFAULT_UNKNOWN_TAG_NAME, $description);
19+
}
20+
21+
public function __toString(): string
22+
{
23+
return \sprintf('@%s', $this->description);
24+
}
25+
}

Diff for: src/DocBlock/Tag/VarTag/VarTagFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use TypeLang\Parser\Parser as TypesParser;
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
9-
use TypeLang\PHPDoc\DocBlock\Content\OptionalVariableNameReader;
10-
use TypeLang\PHPDoc\DocBlock\Content\Stream;
11-
use TypeLang\PHPDoc\DocBlock\Content\TypeParserReader;
129
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
10+
use TypeLang\PHPDoc\Parser\Content\OptionalVariableNameReader;
11+
use TypeLang\PHPDoc\Parser\Content\Stream;
12+
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
1313
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1414

1515
/**

Diff for: src/DocBlock/Content/IdentifierReader.php renamed to src/Parser/Content/IdentifierReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
use TypeLang\PHPDoc\Exception\InvalidTagException;
88

Diff for: src/DocBlock/Content/OptionalIdentifierReader.php renamed to src/Parser/Content/OptionalIdentifierReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
/**
88
* @template-extends Reader<non-empty-string|null>

Diff for: src/DocBlock/Content/OptionalTypeParserReader.php renamed to src/Parser/Content/OptionalTypeParserReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
use TypeLang\Parser\Exception\ParserExceptionInterface;
88
use TypeLang\Parser\Node\Stmt\TypeStatement;

Diff for: src/DocBlock/Content/OptionalValueReader.php renamed to src/Parser/Content/OptionalValueReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
/**
88
* @template T of non-empty-string

Diff for: src/DocBlock/Content/OptionalVariableNameReader.php renamed to src/Parser/Content/OptionalVariableNameReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
/**
88
* @template-extends Reader<non-empty-string|null>

Diff for: src/DocBlock/Content/Reader.php renamed to src/Parser/Content/Reader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
/**
88
* @template T of mixed

Diff for: src/DocBlock/Content/Stream.php renamed to src/Parser/Content/Stream.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
use TypeLang\PHPDoc\DocBlock\Description\DescriptionInterface;
88
use TypeLang\PHPDoc\Exception\InvalidTagException;

Diff for: src/DocBlock/Content/TypeParserReader.php renamed to src/Parser/Content/TypeParserReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
use TypeLang\Parser\Exception\ParserExceptionInterface;
88
use TypeLang\Parser\Node\Stmt\TypeStatement;

Diff for: src/DocBlock/Content/ValueReader.php renamed to src/Parser/Content/ValueReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
use TypeLang\PHPDoc\Exception\InvalidTagException;
88

Diff for: src/DocBlock/Content/VariableNameReader.php renamed to src/Parser/Content/VariableNameReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\DocBlock\Content;
5+
namespace TypeLang\PHPDoc\Parser\Content;
66

77
use TypeLang\PHPDoc\Exception\InvalidTagException;
88

Diff for: src/Parser/Tag/RegexTagParser.php

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

55
namespace TypeLang\PHPDoc\Parser\Tag;
66

7+
use TypeLang\PHPDoc\DocBlock\Tag\UnknownTag;
78
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactory;
89
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
910
use TypeLang\PHPDoc\DocBlock\Tag\InvalidTag;
@@ -67,7 +68,7 @@ public function parse(string $tag, DescriptionParserInterface $parser): TagInter
6768
try {
6869
$name = $this->getTagName($tag);
6970
} catch (InvalidTagNameException $e) {
70-
return new InvalidTag($e, description: $tag);
71+
return new UnknownTag($e, description: $tag);
7172
}
7273

7374
/** @var non-empty-string $name */

0 commit comments

Comments
 (0)