Skip to content

Commit 3630a3a

Browse files
committed
Reorganize kernel
1 parent 1e260df commit 3630a3a

File tree

94 files changed

+1972
-723
lines changed

Some content is hidden

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

94 files changed

+1972
-723
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
<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>
1010
<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>
1111
<a href="https://raw.githubusercontent.com/php-type-language/phpdoc/blob/master/LICENSE"><img src="https://poser.pugx.org/type-lang/phpdoc/license?style=for-the-badge" alt="License MIT"></a>
12+
<a href="https://github.com/xepozz/meta-storm-idea-plugin"><img src="https://img.shields.io/static/v1?label=Powered+by&message=Meta+Storm&color=db5860&style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB3aWR0aD0iMTExIiBoZWlnaHQ9IjExMSIgdmlld0JveD0iMCAwIDExMSAxMTEiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTYwLjQ2MTcgOEwzMC4xNjU0IDguMjQ3OUMyNy4yNDYgOC4yNzE3OSAyNC42NDggMTAuMTA1IDIzLjY0NyAxMi44NDc1TDAuNDMwNTkgNzYuODMxNEMtMS4yNDQ1OSA4MS40MjA4IDIuMTc4MDUgODYuMjcxMyA3LjA2MzUzIDg2LjIzMTNMMzIuMTE5NyA4Ni4wMjYzTDM1LjQxNDcgNzYuOTk5TDkuODczOTEgNzcuMjA4TDMxLjYyNTkgMTcuMjM2Mkw1Ny4xNjY2IDE3LjAyNzNMNjAuNDYxNyA4WiIgZmlsbD0iI0FGQjFCMyIvPjxwYXRoIGQ9Ik00OS40MTQ5IDEwMi45OTlMNzkuNzEyMiAxMDIuOTk5QzgyLjYzMTcgMTAyLjk5OSA4NS4yNDQ2IDEwMS4xODcgODYuMjY4IDk4LjQ1MjlMMTEwLjAxMyAzNC40NTI0QzExMS43MjYgMjkuODc2OCAxMDguMzQzIDI0Ljk5ODUgMTAzLjQ1NyAyNC45OTg1TDc4LjQwMDQgMjQuOTk4NUw3NS4wMzE2IDMzLjk5ODVMMTAwLjU3MyAzMy45OTg1TDc4LjMyNTMgOTMuOTk5TDUyLjc4MzcgOTMuOTk5TDQ5LjQxNDkgMTAyLjk5OVoiIGZpbGw9IiNBRkIxQjMiLz48cGF0aCBkPSJNMjIgNjFMODYgOEw1NyA1MEw4OS45OTk3IDQ5Ljk5OTdMMjYgMTAzTDU1IDYxSDIyWiIgZmlsbD0iI0M3NTQ1MCIvPjwvc3ZnPg==" alt="MetaStorm"></a>
1213
</p>
1314
<p align="center">
14-
<a href="https://github.com/php-type-language/phpdoc/actions"><img src="https://github.com/php-type-language/phpdoc/workflows/tests/badge.svg"></a>
15+
<a href="https://github.com/php-type-language/phpdoc/actions/workflows/tests.yml"><img src="https://img.shields.io/github/actions/workflow/status/php-type-language/phpdoc/tests.yml?label=Tests&style=flat-square&logo=unpkg"></a>
16+
<a href="https://github.com/php-type-language/phpdoc/actions/workflows/codestyle.yml"><img src="https://img.shields.io/github/actions/workflow/status/php-type-language/phpdoc/codestyle.yml?label=PER-2+CodeStyle&style=flat-square&logo=telegraph"></a>
17+
<a href="https://github.com/php-type-language/phpdoc/actions/workflows/static-analysis.yml"><img src="https://img.shields.io/github/actions/workflow/status/php-type-language/phpdoc/static-analysis.yml?label=PHPStan&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAGb0lEQVR42u1Xe1BUZRS/y4Kg8oiR3FCCBUySESZBRCiaBnmEsOzeSzsg+KxYYO9dEEftNRqZjx40FRZkT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for TypeLang PHPDoc Parser.
@@ -45,12 +48,13 @@ var_dump($result);
4548
```
4649

4750
**Expected Output:**
51+
4852
```php
4953
TypeLang\PHPDoc\DocBlock {
50-
-description: TypeLang\PHPDoc\Tag\Description\Description {
54+
-description: TypeLang\PHPDoc\DocBlock\Description\Description {
5155
-template: "Example description %1$s and blah-blah-blah."
5256
-tags: array:1 [
53-
0 => TypeLang\PHPDoc\Tag\Tag {
57+
0 => TypeLang\PHPDoc\DocBlock\Tag {
5458
#description: TypeLang\PHPDoc\Tag\Description\Description {
5559
-template: "some"
5660
-tags: []
@@ -60,21 +64,21 @@ TypeLang\PHPDoc\DocBlock {
6064
]
6165
}
6266
-tags: array:3 [
63-
0 => TypeLang\PHPDoc\Tag\Tag {
67+
0 => TypeLang\PHPDoc\DocBlock\Tag {
6468
#description: TypeLang\PHPDoc\Tag\Description\Description {
6569
-template: "("foo")"
6670
-tags: []
6771
}
6872
#name: "Example\Annotation"
6973
}
70-
1 => TypeLang\PHPDoc\Tag\Tag {
74+
1 => TypeLang\PHPDoc\DocBlock\Tag {
7175
#description: TypeLang\PHPDoc\Tag\Description\Description {
7276
-template: "array<non-empty-string, TypeStatement>"
7377
-tags: []
7478
}
7579
#name: "return"
7680
}
77-
2 => TypeLang\PHPDoc\Tag\Tag {
81+
2 => TypeLang\PHPDoc\DocBlock\Tag {
7882
#description: TypeLang\PHPDoc\Tag\Description\Description {
7983
-template: "\Throwable"
8084
-tags: []

composer.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
"php": "^8.1",
1313
"type-lang/parser": "^1.4"
1414
},
15+
"replace": {
16+
"type-lang/phpdoc-docblock": "*"
17+
},
1518
"autoload": {
1619
"psr-4": {
17-
"TypeLang\\PHPDoc\\": "src"
20+
"TypeLang\\PHPDoc\\": "src",
21+
"TypeLang\\PHPDoc\\DocBlock\\": "libs/phpdoc-docblock/src"
1822
}
1923
},
2024
"require-dev": {
2125
"friendsofphp/php-cs-fixer": "^3.70",
26+
"phpdocumentor/reflection-docblock": "^5.6",
2227
"phpstan/phpstan": "^2.1",
2328
"phpstan/phpstan-strict-rules": "^2.0",
2429
"phpunit/phpunit": "^10.5|^11.0|^12.0",
@@ -27,8 +32,12 @@
2732
},
2833
"autoload-dev": {
2934
"psr-4": {
35+
"TypeLang\\PHPDoc\\DocBlock\\Tests\\": "libs/phpdoc-docblock/tests",
3036
"TypeLang\\PHPDoc\\Tests\\": "tests"
31-
}
37+
},
38+
"files": [
39+
"libs/phpdoc-docblock/src/polyfill.php"
40+
]
3241
},
3342
"extra": {
3443
"branch-alias": {
@@ -46,18 +55,18 @@
4655
}
4756
},
4857
"scripts": {
49-
"test": ["@test:unit", "@test:functional"],
58+
"test": [
59+
"@test:unit",
60+
"@test:functional"
61+
],
5062
"test:unit": "phpunit --testdox --testsuite=unit",
5163
"test:functional": "phpunit --testsuite=functional",
52-
5364
"linter": "@linter:check",
5465
"linter:check": "phpstan analyse --configuration phpstan.neon",
5566
"linter:baseline": "phpstan analyse --configuration phpstan.neon --generate-baseline",
56-
5767
"phpcs": "@phpcs:check",
5868
"phpcs:check": "php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --dry-run --verbose --diff",
5969
"phpcs:fix": "php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --verbose --diff",
60-
6170
"dev:merge": "monorepo-builder merge"
6271
},
6372
"minimum-stability": "dev",

libs/phpdoc-docblock/composer.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "type-lang/phpdoc-docblock",
3+
"type": "library",
4+
"keywords": ["language", "php", "phpdoc", "docblock", "tags", "dictionary"],
5+
"license": "MIT",
6+
"support": {
7+
"source": "https://github.com/php-type-language/phpdoc-docblock",
8+
"issues": "https://github.com/php-type-language/phpdoc-docblock/issues"
9+
},
10+
"require": {
11+
"php": "^8.1",
12+
"type-lang/parser": "^1.4"
13+
},
14+
"autoload": {
15+
"psr-4": {
16+
"TypeLang\\PHPDoc\\DocBlock\\": "src"
17+
},
18+
"files": [
19+
"src/polyfill.php"
20+
]
21+
},
22+
"require-dev": {
23+
"friendsofphp/php-cs-fixer": "^3.70",
24+
"phpstan/phpstan": "^2.1",
25+
"phpstan/phpstan-strict-rules": "^2.0",
26+
"phpunit/phpunit": "^10.5|^11.0|^12.0",
27+
"symfony/var-dumper": "^5.4|^6.0|^7.0",
28+
"phpdocumentor/reflection-docblock": "^5.6"
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"TypeLang\\PHPDoc\\DocBlock\\Tests\\": "tests"
33+
}
34+
},
35+
"extra": {
36+
"branch-alias": {
37+
"dev-master": "1.x-dev",
38+
"dev-main": "1.x-dev"
39+
}
40+
},
41+
"config": {
42+
"sort-packages": true,
43+
"platform-check": true,
44+
"bin-compat": "full",
45+
"optimize-autoloader": true,
46+
"preferred-install": {
47+
"*": "dist"
48+
}
49+
},
50+
"scripts": {
51+
"test": ["@test:unit", "@test:functional"],
52+
"test:unit": "phpunit --testdox --testsuite=unit",
53+
"test:functional": "phpunit --testsuite=functional",
54+
55+
"linter": "@linter:check",
56+
"linter:check": "phpstan analyse --configuration phpstan.neon",
57+
"linter:baseline": "phpstan analyse --configuration phpstan.neon --generate-baseline",
58+
59+
"phpcs": "@phpcs:check",
60+
"phpcs:check": "php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --dry-run --verbose --diff",
61+
"phpcs:fix": "php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --verbose --diff"
62+
},
63+
"minimum-stability": "dev",
64+
"prefer-stable": true
65+
}

src/Tag/Description/Description.php renamed to libs/phpdoc-docblock/src/Description/Description.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\Tag\Description;
5+
namespace TypeLang\PHPDoc\DocBlock\Description;
66

77
class Description implements DescriptionInterface
88
{
@@ -30,11 +30,15 @@ public static function fromStringable(string|\Stringable $description): Descript
3030
*/
3131
public static function fromStringableOrNull(string|\Stringable|null $description): ?DescriptionInterface
3232
{
33-
if ($description === null) {
33+
if ($description instanceof DescriptionInterface) {
34+
return $description;
35+
}
36+
37+
if ($description === null || ((string) $description) === '') {
3438
return null;
3539
}
3640

37-
return self::fromStringable($description);
41+
return new self($description);
3842
}
3943

4044
public function __toString(): string

src/Tag/Description/DescriptionInterface.php renamed to libs/phpdoc-docblock/src/Description/DescriptionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\Tag\Description;
5+
namespace TypeLang\PHPDoc\DocBlock\Description;
66

77
/**
88
* Any class that implements this interface is a description object
Lines changed: 19 additions & 0 deletions
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\DocBlock\Description;
6+
7+
/**
8+
* Representation of any entry that contain an description.
9+
*/
10+
interface DescriptionProviderInterface extends OptionalDescriptionProviderInterface
11+
{
12+
/**
13+
* Gets description object which can be represented as a {@see string}
14+
* and contains additional information.
15+
*
16+
* @readonly
17+
*/
18+
public DescriptionInterface $description { get; }
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\DocBlock\Description;
6+
7+
/**
8+
* Representation of any entry that MAY contain an optional description.
9+
*/
10+
interface OptionalDescriptionProviderInterface
11+
{
12+
/**
13+
* Gets optional description object which can be represented as
14+
* a {@see string} and contains additional information or {@see null}
15+
* in case of description is not defined in the entry.
16+
*
17+
* @readonly
18+
*/
19+
public ?DescriptionInterface $description { get; }
20+
}

src/Tag/Description/TaggedDescription.php renamed to libs/phpdoc-docblock/src/Description/TaggedDescription.php

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\PHPDoc\Tag\Description;
5+
namespace TypeLang\PHPDoc\DocBlock\Description;
66

7-
use TypeLang\PHPDoc\Tag\TagInterface;
7+
use TypeLang\PHPDoc\DocBlock\Tag\TagInterface;
88

99
/**
10-
* @template-implements \ArrayAccess<array-key, TagInterface|DescriptionInterface|null>
11-
* @template-implements \IteratorAggregate<array-key, TagInterface|DescriptionInterface>
10+
* @template-implements \ArrayAccess<array-key, TagInterface|null>
11+
* @template-implements \IteratorAggregate<array-key, TagInterface>
1212
*/
1313
class TaggedDescription implements
1414
TaggedDescriptionInterface,
@@ -18,54 +18,48 @@ class TaggedDescription implements
1818
/**
1919
* @var list<TagInterface|DescriptionInterface>
2020
*/
21-
private readonly array $components;
21+
public readonly array $components;
22+
23+
/**
24+
* @var list<TagInterface>
25+
*/
26+
public readonly array $tags;
2227

2328
/**
2429
* @param iterable<array-key, TagInterface|DescriptionInterface> $components
2530
*/
2631
public function __construct(iterable $components = [])
2732
{
2833
$this->components = \array_values([...$components]);
34+
35+
$this->tags = $this->getTagsFromComponents($this->components);
2936
}
3037

3138
/**
32-
* @return list<TagInterface|DescriptionInterface>
39+
* @param iterable<mixed, object> $components
40+
* @return list<TagInterface>
3341
*/
34-
public function getComponents(): iterable
42+
private function getTagsFromComponents(iterable $components): array
3543
{
36-
return $this->components;
37-
}
44+
$result = [];
3845

39-
public function getTags(): iterable
40-
{
41-
foreach ($this->components as $component) {
46+
foreach ($components as $component) {
4247
if ($component instanceof TagInterface) {
43-
yield $component;
48+
$result[] = $component;
4449
}
4550
}
46-
}
4751

48-
public function getIterator(): \Traversable
49-
{
50-
return new \ArrayIterator($this->components);
51-
}
52-
53-
/**
54-
* @return int<0, max>
55-
*/
56-
public function count(): int
57-
{
58-
return \count($this->components);
52+
return $result;
5953
}
6054

6155
public function offsetExists(mixed $offset): bool
6256
{
63-
return isset($this->components[$offset]);
57+
return isset($this->tags[$offset]);
6458
}
6559

66-
public function offsetGet(mixed $offset): TagInterface|DescriptionInterface|null
60+
public function offsetGet(mixed $offset): ?TagInterface
6761
{
68-
return $this->components[$offset] ?? null;
62+
return $this->tags[$offset] ?? null;
6963
}
7064

7165
/**
@@ -84,8 +78,29 @@ public function offsetUnset(mixed $offset): void
8478
throw new \BadMethodCallException(static::class . ' objects are immutable');
8579
}
8680

81+
public function getIterator(): \Traversable
82+
{
83+
return new \ArrayIterator($this->tags);
84+
}
85+
86+
/**
87+
* @return int<0, max>
88+
*/
89+
public function count(): int
90+
{
91+
return \count($this->tags);
92+
}
93+
8794
public function __toString(): string
8895
{
89-
return \implode('', $this->components);
96+
$result = [];
97+
98+
foreach ($this->components as $component) {
99+
$result[] = $component instanceof TagInterface
100+
? \sprintf('{%s}', $component)
101+
: $component;
102+
}
103+
104+
return \implode('', $result);
90105
}
91106
}

0 commit comments

Comments
 (0)