Skip to content

Commit 0c6376a

Browse files
committed
Split "no type" and "invalid type" to 2 separate exceptions
1 parent 1f80a62 commit 0c6376a

File tree

14 files changed

+45
-31
lines changed

14 files changed

+45
-31
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"require-dev": {
2828
"friendsofphp/php-cs-fixer": "^3.70",
29+
"jetbrains/phpstorm-attributes": "^1.0",
2930
"phpstan/phpstan": "^2.1",
3031
"phpstan/phpstan-strict-rules": "^2.0",
3132
"phpunit/phpunit": "^10.5|^11.0|^12.0",

resources/.meta-storm.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
<meta-storm xmlns="meta-storm">
33
<definitions>
44

5-
<classConstructor class="\TypeLang\PHPDoc\ParserInterface"
6-
argument="1">
5+
<classMethod class="\TypeLang\PHPDoc\ParserInterface"
6+
method="parse"
7+
argument="0">
78
<languageInjection language="InjectablePHP" />
8-
</classConstructor>
9+
</classMethod>
910

10-
<classConstructor class="\TypeLang\PHPDoc\Parser"
11-
argument="1">
11+
<classMethod class="\TypeLang\PHPDoc\Parser"
12+
method="parse"
13+
argument="0">
1214
<languageInjection language="InjectablePHP" />
13-
</classConstructor>
15+
</classMethod>
1416

1517
</definitions>
1618
</meta-storm>

src/DocBlock/Tag/MethodTag/MethodTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use TypeLang\PHPDoc\Parser\Content\OptionalTypeReader;
1212
use TypeLang\PHPDoc\Parser\Content\OptionalValueReader;
1313
use TypeLang\PHPDoc\Parser\Content\Stream;
14-
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
14+
use TypeLang\PHPDoc\Parser\Content\TypeReader;
1515
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1616

1717
/**
@@ -30,7 +30,7 @@ public function create(string $tag, string $content, DescriptionParserInterface
3030
$stream = new Stream($tag, $content);
3131

3232
$isStatic = $stream->apply(new OptionalValueReader('static')) !== null;
33-
$returnType = $stream->apply(new TypeParserReader($this->parser));
33+
$returnType = $stream->apply(new TypeReader($this->parser));
3434
$callableType = $stream->apply(new OptionalTypeReader($this->parser));
3535

3636
// In case of return type has not been defined then we swap first

src/DocBlock/Tag/ParamTag/ParamTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
99
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
1010
use TypeLang\PHPDoc\Parser\Content\Stream;
11-
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
11+
use TypeLang\PHPDoc\Parser\Content\TypeReader;
1212
use TypeLang\PHPDoc\Parser\Content\VariableNameReader;
1313
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1414

@@ -39,7 +39,7 @@ public function create(string $tag, string $content, DescriptionParserInterface
3939
$output = $variadic = false;
4040

4141
if (!$this->isVariable($stream->value)) {
42-
$type = $stream->apply(new TypeParserReader($this->parser));
42+
$type = $stream->apply(new TypeReader($this->parser));
4343
}
4444

4545
if (\str_starts_with($stream->value, '&')) {

src/DocBlock/Tag/PropertyTag/PropertyTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
99
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
1010
use TypeLang\PHPDoc\Parser\Content\Stream;
11-
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
11+
use TypeLang\PHPDoc\Parser\Content\TypeReader;
1212
use TypeLang\PHPDoc\Parser\Content\VariableNameReader;
1313
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1414

@@ -29,7 +29,7 @@ public function create(string $tag, string $content, DescriptionParserInterface
2929
$type = null;
3030

3131
if (!\str_starts_with($stream->value, '$')) {
32-
$type = $stream->apply(new TypeParserReader($this->parser));
32+
$type = $stream->apply(new TypeReader($this->parser));
3333
}
3434

3535
$variable = $stream->apply(new VariableNameReader());

src/DocBlock/Tag/ReturnTag/ReturnTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
99
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
1010
use TypeLang\PHPDoc\Parser\Content\Stream;
11-
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
11+
use TypeLang\PHPDoc\Parser\Content\TypeReader;
1212
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1313

1414
/**
@@ -28,7 +28,7 @@ public function create(string $tag, string $content, DescriptionParserInterface
2828

2929
return new ReturnTag(
3030
name: $tag,
31-
type: $stream->apply(new TypeParserReader($this->parser)),
31+
type: $stream->apply(new TypeReader($this->parser)),
3232
description: $stream->toOptionalDescription($descriptions),
3333
);
3434
}

src/DocBlock/Tag/TemplateExtendsTag/TemplateExtendsTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
99
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
1010
use TypeLang\PHPDoc\Parser\Content\Stream;
11-
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
11+
use TypeLang\PHPDoc\Parser\Content\TypeReader;
1212
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1313

1414
/**
@@ -27,7 +27,7 @@ public function create(string $tag, string $content, DescriptionParserInterface
2727
{
2828
$stream = new Stream($tag, $content);
2929

30-
$type = $stream->apply(new TypeParserReader($this->parser));
30+
$type = $stream->apply(new TypeReader($this->parser));
3131

3232
return new TemplateExtendsTag(
3333
name: $tag,

src/DocBlock/Tag/ThrowsTag/ThrowsTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use TypeLang\Parser\ParserInterface as TypesParserInterface;
99
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
1010
use TypeLang\PHPDoc\Parser\Content\Stream;
11-
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
11+
use TypeLang\PHPDoc\Parser\Content\TypeReader;
1212
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1313

1414
/**
@@ -28,7 +28,7 @@ public function create(string $tag, string $content, DescriptionParserInterface
2828

2929
return new ThrowsTag(
3030
name: $tag,
31-
type: $stream->apply(new TypeParserReader($this->parser)),
31+
type: $stream->apply(new TypeReader($this->parser)),
3232
description: $stream->toOptionalDescription($descriptions),
3333
);
3434
}

src/DocBlock/Tag/VarTag/VarTagFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
1010
use TypeLang\PHPDoc\Parser\Content\OptionalVariableNameReader;
1111
use TypeLang\PHPDoc\Parser\Content\Stream;
12-
use TypeLang\PHPDoc\Parser\Content\TypeParserReader;
12+
use TypeLang\PHPDoc\Parser\Content\TypeReader;
1313
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1414

1515
/**
@@ -27,7 +27,7 @@ public function create(string $tag, string $content, DescriptionParserInterface
2727
{
2828
$stream = new Stream($tag, $content);
2929

30-
$type = $stream->apply(new TypeParserReader($this->parser));
30+
$type = $stream->apply(new TypeReader($this->parser));
3131
$variable = $stream->apply(new OptionalVariableNameReader());
3232

3333
return new VarTag(

src/Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace TypeLang\PHPDoc;
66

7+
use JetBrains\PhpStorm\Language;
78
use TypeLang\PHPDoc\DocBlock\DocBlock;
89
use TypeLang\PHPDoc\DocBlock\Tag\Factory\MutableTagFactoryInterface;
910
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactory;
@@ -68,7 +69,7 @@ public function register(string|array $tags, TagFactoryInterface $delegate): voi
6869
/**
6970
* @throws RuntimeExceptionInterface
7071
*/
71-
public function parse(string $docblock): DocBlock
72+
public function parse(#[Language('InjectablePHP')] string $docblock): DocBlock
7273
{
7374
$mapper = new SourceMap();
7475

0 commit comments

Comments
 (0)