Skip to content

Commit 24e1486

Browse files
committed
add temp patches
1 parent 1483f56 commit 24e1486

File tree

4 files changed

+95
-5
lines changed

4 files changed

+95
-5
lines changed

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,14 @@
128128
"patches/DependencyChecker.patch",
129129
"patches/Resolver.patch"
130130
],
131-
"symfony/console": [
132-
"patches/OutputFormatter.patch"
133-
]
134-
}
131+
"symfony/console": [
132+
"patches/OutputFormatter.patch"
133+
],
134+
"phpstan/phpdoc-parser": [
135+
"patches/TypeAliasTagValueNode.patch",
136+
"patches/PhpDocParser.patch"
137+
]
138+
}
135139
},
136140
"autoload": {
137141
"psr-4": {

patches/PhpDocParser.patch

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--- src/Parser/PhpDocParser.php
2+
+++ src/Parser/PhpDocParser.php
3+
@@ -1067,6 +1067,21 @@
4+
$alias = $tokens->currentTokenValue();
5+
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
6+
7+
+ $templateTypes = [];
8+
+ if ($tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
9+
+ do {
10+
+ $startLine = $tokens->currentTokenLine();
11+
+ $startIndex = $tokens->currentTokenIndex();
12+
+ $templateTypes[] = $this->enrichWithAttributes(
13+
+ $tokens,
14+
+ $this->typeParser->parseTemplateTagValue($tokens),
15+
+ $startLine,
16+
+ $startIndex,
17+
+ );
18+
+ } while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA));
19+
+ $tokens->consumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET);
20+
+ }
21+
+
22+
// support phan-type/psalm-type syntax
23+
$tokens->tryConsumeTokenType(Lexer::TOKEN_EQUAL);
24+
25+
@@ -1087,12 +1102,13 @@
26+
}
27+
}
28+
29+
- return new Ast\PhpDoc\TypeAliasTagValueNode($alias, $type);
30+
+ return new Ast\PhpDoc\TypeAliasTagValueNode($alias, $type, $templateTypes);
31+
} catch (ParserException $e) {
32+
$this->parseOptionalDescription($tokens, false);
33+
return new Ast\PhpDoc\TypeAliasTagValueNode(
34+
$alias,
35+
$this->enrichWithAttributes($tokens, new Ast\Type\InvalidTypeNode($e), $startLine, $startIndex),
36+
+ $templateTypes,
37+
);
38+
}
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--- src/Ast/PhpDoc/TypeAliasTagValueNode.php
2+
+++ src/Ast/PhpDoc/TypeAliasTagValueNode.php
3+
@@ -4,6 +4,7 @@
4+
5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
7+
+use function implode;
8+
use function trim;
9+
10+
class TypeAliasTagValueNode implements PhpDocTagValueNode
11+
@@ -15,15 +16,25 @@
12+
13+
public TypeNode $type;
14+
15+
- public function __construct(string $alias, TypeNode $type)
16+
+ /** @var TemplateTagValueNode[] */
17+
+ public array $templateTypes;
18+
+
19+
+ /**
20+
+ * @param TemplateTagValueNode[] $templateTypes
21+
+ */
22+
+ public function __construct(string $alias, TypeNode $type, array $templateTypes = [])
23+
{
24+
$this->alias = $alias;
25+
$this->type = $type;
26+
+ $this->templateTypes = $templateTypes;
27+
}
28+
29+
public function __toString(): string
30+
{
31+
- return trim("{$this->alias} {$this->type}");
32+
+ $templateTypes = $this->templateTypes !== []
33+
+ ? '<' . implode(', ', $this->templateTypes) . '>'
34+
+ : '';
35+
+ return trim("{$this->alias}{$templateTypes} {$this->type}");
36+
}
37+
38+
/**
39+
@@ -31,7 +42,7 @@
40+
*/
41+
public static function __set_state(array $properties): self
42+
{
43+
- $instance = new self($properties['alias'], $properties['type']);
44+
+ $instance = new self($properties['alias'], $properties['type'], $properties['templateTypes'] ?? []);
45+
if (isset($properties['attributes'])) {
46+
foreach ($properties['attributes'] as $key => $value) {
47+
$instance->setAttribute($key, $value);

src/PhpDoc/PhpDocNodeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public function resolveTypeAliasTags(PhpDocNode $phpDocNode, NameScope $nameScop
522522
foreach ($phpDocNode->getTypeAliasTagValues($tagName) as $typeAliasTagValue) {
523523
$alias = $typeAliasTagValue->alias;
524524
$typeNode = $typeAliasTagValue->type;
525-
$resolved[$alias] = new TypeAliasTag($alias, $typeNode, $nameScope, $typeAliasTagValue->templateTypes ?? []);
525+
$resolved[$alias] = new TypeAliasTag($alias, $typeNode, $nameScope, $typeAliasTagValue->templateTypes);
526526
}
527527
}
528528

0 commit comments

Comments
 (0)