From 25aa933e67f54b5e8156218d24d159cbbbd55a5a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 7 Nov 2024 14:54:37 +0100 Subject: [PATCH] add support for phpstan/phpdoc-parser 2 --- composer.json | 2 +- src/TypeResolver.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 13045ef..5c280e3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", - "phpstan/phpdoc-parser": "^1.18", + "phpstan/phpdoc-parser": "^1.18|^2.0", "doctrine/deprecations": "^1.0" }, "require-dev": { diff --git a/src/TypeResolver.php b/src/TypeResolver.php index a820fee..774b9b7 100644 --- a/src/TypeResolver.php +++ b/src/TypeResolver.php @@ -98,6 +98,7 @@ use PHPStan\PhpDocParser\Parser\ParserException; use PHPStan\PhpDocParser\Parser\TokenIterator; use PHPStan\PhpDocParser\Parser\TypeParser; +use PHPStan\PhpDocParser\ParserConfig; use RuntimeException; use function array_filter; @@ -189,8 +190,15 @@ final class TypeResolver public function __construct(?FqsenResolver $fqsenResolver = null) { $this->fqsenResolver = $fqsenResolver ?: new FqsenResolver(); - $this->typeParser = new TypeParser(new ConstExprParser()); - $this->lexer = new Lexer(); + + if (class_exists(ParserConfig::class)) { + $parserConfig = new ParserConfig([]); + $this->typeParser = new TypeParser($parserConfig, new ConstExprParser($parserConfig)); + $this->lexer = new Lexer($parserConfig); + } else { + $this->typeParser = new TypeParser(new ConstExprParser()); + $this->lexer = new Lexer(); + } } /**