Skip to content

Commit 2cf308a

Browse files
committed
Improve and rewrite phpdoc parser
1 parent a56885e commit 2cf308a

File tree

1,126 files changed

+2471
-10377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,126 files changed

+2471
-10377
lines changed

Diff for: .php-cs-fixer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
'syntax' => 'short',
1313
],
1414
])
15-
->setCacheFile(__DIR__ . '/vendor/.php-cs-fixer.cache')
15+
->setCacheFile(__DIR__ . '/vendor/.cache.php-cs-fixer')
1616
->setFinder($files);

Diff for: README.md

+37-7
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,58 @@
77
---
88

99
<p align="center">
10-
<a href="https://packagist.org/packages/type-lang/phpdoc-parser"><img src="https://poser.pugx.org/type-lang/phpdoc-parser/require/php?style=for-the-badge" alt="PHP 8.1+"></a>
11-
<a href="https://packagist.org/packages/type-lang/phpdoc-parser"><img src="https://poser.pugx.org/type-lang/phpdoc-parser/version?style=for-the-badge" alt="Latest Stable Version"></a>
12-
<a href="https://packagist.org/packages/type-lang/phpdoc-parser"><img src="https://poser.pugx.org/type-lang/phpdoc-parser/v/unstable?style=for-the-badge" alt="Latest Unstable Version"></a>
13-
<a href="https://raw.githubusercontent.com/php-type-language/phpdoc-parser/blob/master/LICENSE"><img src="https://poser.pugx.org/type-lang/phpdoc-parser/license?style=for-the-badge" alt="License MIT"></a>
10+
<a href="https://packagist.org/packages/type-lang/phpdoc"><img src="https://poser.pugx.org/type-lang/phpdoc/require/php?style=for-the-badge" alt="PHP 8.1+"></a>
11+
<a href="https://packagist.org/packages/type-lang/phpdoc"><img src="https://poser.pugx.org/type-lang/phpdoc/version?style=for-the-badge" alt="Latest Stable Version"></a>
12+
<a href="https://packagist.org/packages/type-lang/phpdoc"><img src="https://poser.pugx.org/type-lang/phpdoc/v/unstable?style=for-the-badge" alt="Latest Unstable Version"></a>
13+
<a href="https://raw.githubusercontent.com/php-type-language/phpdoc-parser/blob/master/LICENSE"><img src="https://poser.pugx.org/type-lang/phpdoc/license?style=for-the-badge" alt="License MIT"></a>
1414
</p>
1515
<p align="center">
1616
<a href="https://github.com/php-type-language/phpdoc-parser/actions"><img src="https://github.com/php-type-language/phpdoc-parser/workflows/tests/badge.svg"></a>
1717
</p>
1818

1919
The PHP reference implementation for Type Language PhpDoc Parser.
2020

21-
Read [documentation pages](https://docs.phpdoc.io) for more information.
21+
Read [documentation pages](https://phpdoc.io) for more information.
2222

2323
## Installation
2424

2525
PhpDoc Generator is available as composer repository and can be
2626
installed using the following command in a root of your project:
2727

2828
```sh
29-
$ composer require type-lang/phpdoc-parser
29+
$ composer require type-lang/phpdoc
3030
```
3131

3232
## Quick Start
3333

34-
TODO
34+
```php
35+
use TypeLang\PHPDoc\DocBlockFactory;
36+
37+
$phpdoc = DocBlockFactory::createInstance()
38+
->create(<<<'PHP'
39+
/**
40+
* Example description.
41+
*
42+
* @param non-empty-string $foo Foo param.
43+
* @param int<0, max> $bar Bar param.
44+
*
45+
* @return void Returns nothing.
46+
*/
47+
PHP);
48+
49+
echo $phpdoc->getDescription() . "\n";
50+
// Output: string("Example description.\n")
51+
52+
foreach ($phpdoc->getTags() as $tag) {
53+
echo $tag->getName() . ': '
54+
. $tag->getDescription() . "\n";
55+
// Output 3 lines:
56+
// param: Foo param.
57+
// param: Bar param.
58+
// return: Returns nothing.
59+
}
60+
```
61+
62+
### Supported Tags
63+
64+

Diff for: composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
{
2-
"name": "type-lang/phpdoc-parser",
2+
"name": "type-lang/phpdoc",
33
"type": "library",
4-
"description": "PHP Types Reader",
5-
"keywords": ["language", "php", "reader", "phpdoc", "docblock"],
4+
"description": "PHPDoc",
5+
"keywords": ["language", "php", "phpdoc", "docblock", "tags", "dictionary"],
66
"license": "MIT",
77
"support": {
8-
"source": "https://github.com/php-type-language/phpdoc-parser",
9-
"issues": "https://github.com/php-type-language/phpdoc-parser/issues"
8+
"source": "https://github.com/php-type-language/phpdoc",
9+
"issues": "https://github.com/php-type-language/phpdoc/issues"
1010
},
1111
"require": {
1212
"php": "^8.1",
13-
"psr/http-message": "^1.0|^2.0",
13+
"composer/semver": "^2.0|^3.0",
1414
"type-lang/parser": "^1.0"
1515
},
1616
"autoload": {
1717
"psr-4": {
18-
"TypeLang\\PhpDoc\\Parser\\": "src"
18+
"TypeLang\\PHPDoc\\": "src"
1919
}
2020
},
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "^3.42",
2323
"phpunit/phpunit": "^10.5",
24-
"rector/rector": "^0.18",
24+
"rector/rector": "^1.0",
2525
"vimeo/psalm": "^5.18"
2626
},
2727
"autoload-dev": {
2828
"psr-4": {
29-
"TypeLang\\PhpDoc\\Parser\\Tests\\": "tests"
29+
"TypeLang\\PHPDoc\\Tests\\": "tests"
3030
}
3131
},
3232
"extra": {

Diff for: phpunit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
stopOnFailure="false"
77
processIsolation="false"
88
bootstrap="vendor/autoload.php"
9-
cacheDirectory="vendor/.phpunit.cache"
9+
cacheDirectory="vendor/.cache.phpunit"
1010
backupStaticProperties="false"
1111
>
1212
<testsuites>

Diff for: psalm.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
88
xmlns="https://getpsalm.org/schema/config"
99
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10+
cacheDirectory="vendor/.cache.psalm"
1011
>
1112
<projectFiles>
1213
<directory name="src" />

Diff for: rector.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
use Rector\Config\RectorConfig;
1111
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector;
1212
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
13-
use Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector;
1413
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
1514
use Rector\Set\ValueObject\LevelSetList;
1615
use Rector\Set\ValueObject\SetList;
1716
use Rector\TypeDeclaration\Rector\FunctionLike\AddReturnTypeDeclarationFromYieldsRector;
1817

1918
return static function (RectorConfig $config): void {
2019
$config->paths([__DIR__ . '/src']);
20+
$config->cacheDirectory(__DIR__ . '/vendor/.cache.rector');
2121

2222
$config->sets([
2323
LevelSetList::UP_TO_PHP_81,
@@ -32,7 +32,6 @@
3232
ReadOnlyPropertyRector::class,
3333
CatchExceptionNameMatchingTypeRector::class,
3434
SplitDoubleAssignRector::class,
35-
FinalizePublicClassConstantRector::class,
3635
FlipTypeControlToUseExclusiveTypeRector::class,
3736
ReturnBinaryOrToEarlyReturnRector::class,
3837
LocallyCalledStaticMethodToNonStaticRector::class,

Diff for: src/Description/DescriptionFactoryInterface.php

-15
This file was deleted.

Diff for: src/DocBlock.php

+17-23
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PhpDoc\Parser;
5+
namespace TypeLang\PHPDoc;
66

77
use TypeLang\Parser\Node\SerializableInterface;
8-
use TypeLang\PhpDoc\Parser\DocBlock\Description;
9-
use TypeLang\PhpDoc\Parser\DocBlock\Tag\TagInterface;
10-
use TypeLang\PhpDoc\Parser\DocBlock\TagProvider;
11-
use TypeLang\PhpDoc\Parser\DocBlock\TagProviderInterface;
8+
use TypeLang\PHPDoc\Tag\Description\Description;
9+
use TypeLang\PHPDoc\Tag\Description\DescriptionInterface;
10+
use TypeLang\PHPDoc\Tag\TagInterface;
11+
use TypeLang\PHPDoc\Tag\TagProvider;
12+
use TypeLang\PHPDoc\Tag\TagProviderInterface;
1213

13-
final class DocBlock implements TagProviderInterface, SerializableInterface
14+
/**
15+
* @template-implements \IteratorAggregate<array-key, TagInterface>
16+
*/
17+
final class DocBlock implements
18+
TagProviderInterface,
19+
SerializableInterface,
20+
\IteratorAggregate
1421
{
15-
use TagProvider {
16-
getIterator as private getTagProviderIterator;
17-
}
22+
use TagProvider;
1823

1924
/**
20-
* @param iterable<array-key, TagInterface> $tags
25+
* @param iterable<TagInterface> $tags
2126
*/
2227
public function __construct(
23-
private readonly Description $description = new Description(),
28+
private readonly DescriptionInterface $description = new Description(),
2429
iterable $tags = [],
2530
) {
26-
$this->initializeTags($tags);
27-
}
28-
29-
public function getDescription(): Description
30-
{
31-
return $this->description;
31+
$this->bootTagProvider($tags);
3232
}
3333

3434
/**
@@ -67,10 +67,4 @@ public function jsonSerialize(): array
6767
{
6868
return $this->toArray();
6969
}
70-
71-
public function getIterator(): \Traversable
72-
{
73-
yield from $this->description;
74-
yield from $this->getTagProviderIterator();
75-
}
7670
}

Diff for: src/DocBlock/Description.php

-81
This file was deleted.

Diff for: src/DocBlock/Reader/OptionalTypeReader.php

-38
This file was deleted.

0 commit comments

Comments
 (0)