diff --git a/Extractor/PhpStanExtractor.php b/Extractor/PhpStanExtractor.php index 44888a6..9c8562d 100644 --- a/Extractor/PhpStanExtractor.php +++ b/Extractor/PhpStanExtractor.php @@ -21,6 +21,7 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\PhpDocParser\Parser\TokenIterator; use PHPStan\PhpDocParser\Parser\TypeParser; +use PHPStan\PhpDocParser\ParserConfig; use Symfony\Component\PropertyInfo\PhpStan\NameScopeFactory; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; use Symfony\Component\PropertyInfo\Type; @@ -68,8 +69,14 @@ public function __construct(?array $mutatorPrefixes = null, ?array $accessorPref $this->accessorPrefixes = $accessorPrefixes ?? ReflectionExtractor::$defaultAccessorPrefixes; $this->arrayMutatorPrefixes = $arrayMutatorPrefixes ?? ReflectionExtractor::$defaultArrayMutatorPrefixes; - $this->phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser()); - $this->lexer = new Lexer(); + if (class_exists(ParserConfig::class)) { + $parserConfig = new ParserConfig([]); + $this->phpDocParser = new PhpDocParser($parserConfig, new TypeParser($parserConfig, new ConstExprParser($parserConfig)), new ConstExprParser($parserConfig)); + $this->lexer = new Lexer($parserConfig); + } else { + $this->phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser()); + $this->lexer = new Lexer(); + } $this->nameScopeFactory = new NameScopeFactory(); } diff --git a/composer.json b/composer.json index 0a9879f..5f53648 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "symfony/cache": "^5.4|^6.0|^7.0", "symfony/dependency-injection": "^5.4|^6.0|^7.0", "phpdocumentor/reflection-docblock": "^5.2", - "phpstan/phpdoc-parser": "^1.0" + "phpstan/phpdoc-parser": "^1.0|^2.0" }, "conflict": { "phpdocumentor/reflection-docblock": "<5.2",