Skip to content

Commit 4376113

Browse files
authored
Merge pull request #367 from dereuromark/phpstan-update
Compat with phpstan parser v2
2 parents 123208e + 292aae3 commit 4376113

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"php": ">=8.1",
3535
"cakephp/bake": "^3.0.4",
3636
"cakephp/cakephp": "^5.0.7",
37-
"phpstan/phpdoc-parser": "^1.23.1",
37+
"phpstan/phpdoc-parser": "^1.23.1 || ^2.1.0",
3838
"sebastian/diff": "^5.0 || ^6.0",
3939
"squizlabs/php_codesniffer": "^3.8"
4040
},

src/Annotator/Traits/DocBlockTrait.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPStan\PhpDocParser\Parser\PhpDocParser;
2222
use PHPStan\PhpDocParser\Parser\TokenIterator;
2323
use PHPStan\PhpDocParser\Parser\TypeParser;
24+
use PHPStan\PhpDocParser\ParserConfig;
2425

2526
/**
2627
* Common functionality around doc block parsing and writing.
@@ -36,13 +37,27 @@ trait DocBlockTrait {
3637
protected static function getValueNode(string $tagName, string $tagComment): PhpDocTagValueNode {
3738
static $phpDocParser;
3839
if (!$phpDocParser) {
39-
$constExprParser = new ConstExprParser();
40-
$phpDocParser = new PhpDocParser(new TypeParser($constExprParser), $constExprParser);
40+
if (class_exists(ParserConfig::class)) {
41+
$config = new ParserConfig(usedAttributes: []);
42+
$constExprParser = new ConstExprParser($config);
43+
$phpDocParser = new PhpDocParser($config, new TypeParser($config, $constExprParser), $constExprParser);
44+
} else {
45+
/** @phpstan-ignore-next-line */
46+
$constExprParser = new ConstExprParser();
47+
/** @phpstan-ignore-next-line */
48+
$phpDocParser = new PhpDocParser(new TypeParser($constExprParser), $constExprParser);
49+
}
4150
}
4251

4352
static $phpDocLexer;
4453
if (!$phpDocLexer) {
45-
$phpDocLexer = new Lexer();
54+
if (class_exists(ParserConfig::class)) {
55+
$config = new ParserConfig(usedAttributes: []);
56+
$phpDocLexer = new Lexer($config);
57+
} else {
58+
/** @phpstan-ignore-next-line */
59+
$phpDocLexer = new Lexer();
60+
}
4661
}
4762

4863
return $phpDocParser->parseTagValue(new TokenIterator($phpDocLexer->tokenize($tagComment)), $tagName);

0 commit comments

Comments
 (0)