Skip to content

Commit 679e3ce

Browse files
authored
Merge pull request #212 from xabbuh/phpstan-phpdoc-parser-2
add support for phpstan/phpdoc-parser 2
2 parents 1fb5ba8 + f421ef3 commit 679e3ce

6 files changed

+51
-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

psalm.xml

+22
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,27 @@
3838
<file name="src/TypeResolver.php"/>
3939
</errorLevel>
4040
</RedundantConditionGivenDocblockType>
41+
42+
<InvalidArgument>
43+
<errorLevel type="suppress">
44+
<referencedFunction name="PHPStan\PhpDocParser\Lexer\Lexer::__construct"/>
45+
<referencedFunction name="PHPStan\PhpDocParser\Parser\ConstExprParser::__construct"/>
46+
<referencedFunction name="PHPStan\PhpDocParser\Parser\TypeParser::__construct"/>
47+
</errorLevel>
48+
</InvalidArgument>
49+
50+
<UndefinedDocblockClass>
51+
<errorLevel type="suppress">
52+
<referencedClass name="PHPStan\PhpDocParser\ParserConfig"/>
53+
</errorLevel>
54+
</UndefinedDocblockClass>
55+
56+
<MixedArgument>
57+
<errorLevel type="suppress">
58+
<referencedFunction name="PHPStan\PhpDocParser\Lexer\Lexer::__construct"/>
59+
<referencedFunction name="PHPStan\PhpDocParser\Parser\ConstExprParser::__construct"/>
60+
<referencedFunction name="PHPStan\PhpDocParser\Parser\TypeParser::__construct"/>
61+
</errorLevel>
62+
</MixedArgument>
4163
</issueHandlers>
4264
</psalm>

src/TypeResolver.php

+9-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,14 @@ 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+
$this->typeParser = new TypeParser(new ParserConfig([]), new ConstExprParser(new ParserConfig([])));
196+
$this->lexer = new Lexer(new ParserConfig([]));
197+
} else {
198+
$this->typeParser = new TypeParser(new ConstExprParser());
199+
$this->lexer = new Lexer();
200+
}
194201
}
195202

196203
/**

0 commit comments

Comments
 (0)