Skip to content

Commit 9ee57f8

Browse files
committed
add support for phpstan/phpdoc-parser 2
1 parent 1fb5ba8 commit 9ee57f8

5 files changed

+30
-5
lines changed

composer-require-checker.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"symbol-whitelist" : [
33
"null", "true", "false",
44
"static", "self", "parent",
5-
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor",
5+
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor", "PHPStan\\PhpDocParser\\ParserConfig",
66
"T_NAME_QUALIFIED", "T_NAME_FULLY_QUALIFIED"
77
],
88
"php-core-extensions" : [

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": "^7.3 || ^8.0",
1414
"phpdocumentor/reflection-common": "^2.0",
15-
"phpstan/phpdoc-parser": "^1.18",
15+
"phpstan/phpdoc-parser": "^1.18|^2.0",
1616
"doctrine/deprecations": "^1.0"
1717
},
1818
"require-dev": {

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

+17
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,20 @@ parameters:
77
- tests/benchmark/Assets/*
88
paths:
99
- src
10+
ignoreErrors:
11+
-
12+
message: "#^Parameter \\#1 \\$constExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser\\|null, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
13+
count: 1
14+
path: src/TypeResolver.php
15+
-
16+
message: "#^Parameter \\#1 \\$parseDoctrineAnnotations of class PHPStan\\\\PhpDocParser\\\\Lexer\\\\Lexer constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
17+
count: 1
18+
path: src/TypeResolver.php
19+
-
20+
message: "#^Parameter \\#1 \\$unescapeStrings of class PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
21+
count: 1
22+
path: src/TypeResolver.php
23+
-
24+
message: "#^Parameter \\#2 \\$quoteAwareConstExprString of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#"
25+
count: 1
26+
path: src/TypeResolver.php

src/TypeResolver.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
use PHPStan\PhpDocParser\Parser\ParserException;
9999
use PHPStan\PhpDocParser\Parser\TokenIterator;
100100
use PHPStan\PhpDocParser\Parser\TypeParser;
101+
use PHPStan\PhpDocParser\ParserConfig;
101102
use RuntimeException;
102103

103104
use function array_filter;
@@ -189,8 +190,15 @@ final class TypeResolver
189190
public function __construct(?FqsenResolver $fqsenResolver = null)
190191
{
191192
$this->fqsenResolver = $fqsenResolver ?: new FqsenResolver();
192-
$this->typeParser = new TypeParser(new ConstExprParser());
193-
$this->lexer = new Lexer();
193+
194+
if (class_exists(ParserConfig::class)) {
195+
$parserConfig = new ParserConfig([]);
196+
$this->typeParser = new TypeParser($parserConfig, new ConstExprParser($parserConfig));
197+
$this->lexer = new Lexer($parserConfig);
198+
} else {
199+
$this->typeParser = new TypeParser(new ConstExprParser());
200+
$this->lexer = new Lexer();
201+
}
194202
}
195203

196204
/**

0 commit comments

Comments
 (0)