Skip to content

Commit 4d77ab2

Browse files
committed
fix support for phpstan/phpdoc-parser 2
1 parent cec7536 commit 4d77ab2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Extractor/PhpStanExtractor.php

Lines changed: 9 additions & 2 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
use Symfony\Component\PropertyInfo\PhpStan\NameScopeFactory;
2526
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
2627
use Symfony\Component\PropertyInfo\Type;
@@ -73,8 +74,14 @@ public function __construct(?array $mutatorPrefixes = null, ?array $accessorPref
7374
$this->accessorPrefixes = $accessorPrefixes ?? ReflectionExtractor::$defaultAccessorPrefixes;
7475
$this->arrayMutatorPrefixes = $arrayMutatorPrefixes ?? ReflectionExtractor::$defaultArrayMutatorPrefixes;
7576

76-
$this->phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser());
77-
$this->lexer = new Lexer();
77+
if (class_exists(ParserConfig::class)) {
78+
$parserConfig = new ParserConfig([]);
79+
$this->phpDocParser = new PhpDocParser($parserConfig, new TypeParser($parserConfig, new ConstExprParser($parserConfig)), new ConstExprParser($parserConfig));
80+
$this->lexer = new Lexer($parserConfig);
81+
} else {
82+
$this->phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser());
83+
$this->lexer = new Lexer();
84+
}
7885
$this->nameScopeFactory = new NameScopeFactory();
7986
}
8087

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"symfony/cache": "^4.4|^5.0|^6.0",
3434
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
3535
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
36-
"phpstan/phpdoc-parser": "^1.0",
36+
"phpstan/phpdoc-parser": "^1.0|^2.0",
3737
"doctrine/annotations": "^1.10.4|^2"
3838
},
3939
"conflict": {

0 commit comments

Comments
 (0)