From f421ef3a8bd53989d74adcebbb74641819a2116f 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-require-checker.json | 2 +- composer.json | 2 +- composer.lock | 2 +- phpstan.neon | 17 +++++++++++++++++ psalm.xml | 22 ++++++++++++++++++++++ src/TypeResolver.php | 11 +++++++++-- 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/composer-require-checker.json b/composer-require-checker.json index 137522d..e8eb031 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -2,7 +2,7 @@ "symbol-whitelist" : [ "null", "true", "false", "static", "self", "parent", - "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor", + "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor", "PHPStan\\PhpDocParser\\ParserConfig", "T_NAME_QUALIFIED", "T_NAME_FULLY_QUALIFIED" ], "php-core-extensions" : [ 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/composer.lock b/composer.lock index eec91a0..e05c360 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2d7307b14c95f0d2eb310a28ae73dae0", + "content-hash": "142e0ed9e505415b092f3963da4939cc", "packages": [ { "name": "doctrine/deprecations", diff --git a/phpstan.neon b/phpstan.neon index 6c6f50b..e53acac 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,3 +7,20 @@ parameters: - tests/benchmark/Assets/* paths: - src + ignoreErrors: + - + message: "#^Parameter \\#1 \\$constExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser\\|null, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#" + count: 1 + path: src/TypeResolver.php + - + message: "#^Parameter \\#1 \\$parseDoctrineAnnotations of class PHPStan\\\\PhpDocParser\\\\Lexer\\\\Lexer constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#" + count: 1 + path: src/TypeResolver.php + - + message: "#^Parameter \\#1 \\$unescapeStrings of class PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#" + count: 1 + path: src/TypeResolver.php + - + message: "#^Parameter \\#2 \\$quoteAwareConstExprString of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#" + count: 1 + path: src/TypeResolver.php diff --git a/psalm.xml b/psalm.xml index e72c6d9..2d308a8 100644 --- a/psalm.xml +++ b/psalm.xml @@ -38,5 +38,27 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/TypeResolver.php b/src/TypeResolver.php index a820fee..af57226 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,14 @@ 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)) { + $this->typeParser = new TypeParser(new ParserConfig([]), new ConstExprParser(new ParserConfig([]))); + $this->lexer = new Lexer(new ParserConfig([])); + } else { + $this->typeParser = new TypeParser(new ConstExprParser()); + $this->lexer = new Lexer(); + } } /**