diff --git a/composer.json b/composer.json index 9cd35ed1..4317d7bb 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "webmozart/assert": "^1.9.1", "phpdocumentor/reflection-common": "^2.2", "ext-filter": "*", - "phpstan/phpdoc-parser": "^1.7", + "phpstan/phpdoc-parser": "^1.7 || ^2.0", "doctrine/deprecations": "^1.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index dd6fdbd7..781e355b 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": "8d0008447edbcdb6139a9c64654e5931", + "content-hash": "b2bde20dcc60c275527dc30d72c5e191", "packages": [ { "name": "doctrine/deprecations", @@ -108,23 +108,23 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.9.0", + "version": "1.10.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d" + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/1fb5ba8d045f5dd984ebded5b1cc66f29459422d", - "reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/679e3ce485b99e84c775d28e2e96fade9a7fb50a", + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", - "phpstan/phpdoc-parser": "^1.18" + "phpstan/phpdoc-parser": "^1.18|^2.0" }, "require-dev": { "ext-tokenizer": "*", @@ -160,36 +160,36 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.9.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.10.0" }, - "time": "2024-11-03T20:11:34+00:00" + "time": "2024-11-09T15:12:26+00:00" }, { "name": "phpstan/phpdoc-parser", - "version": "1.33.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" + "reference": "c00d78fb6b29658347f9d37ebe104bffadf36299" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", - "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/c00d78fb6b29658347f9d37ebe104bffadf36299", + "reference": "c00d78fb6b29658347f9d37ebe104bffadf36299", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": "^7.4 || ^8.0" }, "require-dev": { "doctrine/annotations": "^2.0", - "nikic/php-parser": "^4.15", + "nikic/php-parser": "^5.3.0", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.5", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^9.5", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6", "symfony/process": "^5.2" }, "type": "library", @@ -207,9 +207,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/2.0.0" }, - "time": "2024-10-13T11:25:22+00:00" + "time": "2024-10-13T11:29:49+00:00" }, { "name": "webmozart/assert", @@ -2376,14 +2376,14 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": "^7.4 || ^8.0", "ext-filter": "*" }, - "platform-dev": [], + "platform-dev": {}, "platform-overrides": { "php": "7.4.0" }, diff --git a/phpstan.neon b/phpstan.neon index c2365775..7f87991b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,5 +3,55 @@ parameters: ignoreErrors: - '#Method phpDocumentor\\Reflection\\DocBlock\\StandardTagFactory::createTag\(\) should return phpDocumentor\\Reflection\\DocBlock\\Tag but returns mixed#' - '#Offset 2 on array\{string, 28, int\} on left side of \?\? always exists and is not nullable\.#' + - + message: "#^Class PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser constructor invoked with 3 parameters, 1 required\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor invoked with 6 parameters, 3 required\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor invoked with 3 parameters, 2 required\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Parameter \\#1 \\$config of class PHPStan\\\\PhpDocParser\\\\Lexer\\\\Lexer constructor expects PHPStan\\\\PhpDocParser\\\\ParserConfig, true given\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Parameter \\#1 \\$config of class PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser constructor expects PHPStan\\\\PhpDocParser\\\\ParserConfig, true given\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Parameter \\#1 \\$config of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects PHPStan\\\\PhpDocParser\\\\ParserConfig, PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser given\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Parameter \\#1 \\$config of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects PHPStan\\\\PhpDocParser\\\\ParserConfig, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Parameter \\#2 \\$constExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser, true given\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Parameter \\#2 \\$typeParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + + - + message: "#^Parameter \\#3 \\$constantExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser, true given\\.$#" + count: 1 + path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php + paths: - src diff --git a/psalm.xml b/psalm.xml index 6d8fd6b9..ee173f51 100644 --- a/psalm.xml +++ b/psalm.xml @@ -68,5 +68,26 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php index 240e79d9..a43830b2 100644 --- a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php +++ b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.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 RuntimeException; use function ltrim; @@ -44,16 +45,28 @@ class AbstractPHPStanFactory implements Factory public function __construct(PHPStanFactory ...$factories) { - $this->lexer = new Lexer(true); - $constParser = new ConstExprParser(true, true, ['lines' => true, 'indexes' => true]); - $this->parser = new PhpDocParser( - new TypeParser($constParser, true, ['lines' => true, 'indexes' => true]), - $constParser, - true, - true, - ['lines' => true, 'indexes' => true], - true - ); + if (class_exists(ParserConfig::class)) { + $parserConfig = new ParserConfig(['lines' => true, 'indexes' => true]); + $this->lexer = new Lexer($parserConfig); + $constParser = new ConstExprParser($parserConfig); + $this->parser = new PhpDocParser( + $parserConfig, + new TypeParser($parserConfig, $constParser), + $constParser + ); + } else { + $this->lexer = new Lexer(true); + $constParser = new ConstExprParser(true, true, ['lines' => true, 'indexes' => true]); + $this->parser = new PhpDocParser( + new TypeParser($constParser, true, ['lines' => true, 'indexes' => true]), + $constParser, + true, + true, + ['lines' => true, 'indexes' => true], + true + ); + } + $this->factories = $factories; } diff --git a/tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php b/tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php index d97c7f1d..4be14443 100644 --- a/tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php +++ b/tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php @@ -24,19 +24,33 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\PhpDocParser\Parser\TokenIterator; use PHPStan\PhpDocParser\Parser\TypeParser; +use PHPStan\PhpDocParser\ParserConfig; use PHPUnit\Framework\TestCase; +use function class_exists; use function property_exists; abstract class TagFactoryTestCase extends TestCase { public function parseTag(string $tag): PhpDocTagNode { - $lexer = new Lexer(); + if (class_exists(ParserConfig::class)) { + $parserConfig = new ParserConfig([]); + $lexer = new Lexer($parserConfig); + $constParser = new ConstExprParser($parserConfig); + $phpDocParser = new PhpDocParser( + $parserConfig, + new TypeParser($parserConfig, $constParser), + $constParser + ); + } else { + $lexer = new Lexer(); + $constParser = new ConstExprParser(); + $phpDocParser = new PhpDocParser(new TypeParser($constParser), $constParser); + } $tokens = $lexer->tokenize($tag); - $constParser = new ConstExprParser(); - $tagNode = (new PhpDocParser(new TypeParser($constParser), $constParser))->parseTag(new TokenIterator($tokens)); + $tagNode = $phpDocParser->parseTag(new TokenIterator($tokens)); if (property_exists($tagNode->value, 'description') === true) { $tagNode->value->setAttribute('description', $tagNode->value->description); }