From fdbad07a5e25d984d8550fa96d8c94016ecfb0d3 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 12 Nov 2024 14:59:48 +0100 Subject: [PATCH 1/2] fix: properly support phpstan/phpdoc-parser 2 --- composer.json | 2 +- .../Factory/PhpDocResourceMetadataCollectionFactory.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2f6b725b38c..aa0f287b9dc 100644 --- a/composer.json +++ b/composer.json @@ -150,7 +150,7 @@ "justinrainbow/json-schema": "^5.2.1", "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1.1", - "phpstan/phpdoc-parser": "^1.13", + "phpstan/phpdoc-parser": "^1.13|^2.0", "phpstan/phpstan": "^1.10", "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0", diff --git a/src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php b/src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php index 2a5163f424c..38c69a63deb 100644 --- a/src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php +++ b/src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php @@ -25,6 +25,7 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\PhpDocParser\Parser\TokenIterator; use PHPStan\PhpDocParser\Parser\TypeParser; +use PHPStan\PhpDocParser\ParserConfig; /** * Extracts descriptions from PHPDoc. @@ -58,7 +59,11 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn } $phpDocParser = null; $lexer = null; - if (class_exists(PhpDocParser::class)) { + if (class_exists(PhpDocParser::class) && class_exists(ParserConfig::class)) { + $config = new ParserConfig([]); + $phpDocParser = new PhpDocParser($config, new TypeParser($config, new ConstExprParser($config)), new ConstExprParser($config)); + $lexer = new Lexer($config); + } elseif (class_exists(PhpDocParser::class)) { $phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser()); $lexer = new Lexer(); } From 12d74008cdc2a1d456e7c65e0601094d0e184caa Mon Sep 17 00:00:00 2001 From: soyuka Date: Thu, 14 Nov 2024 13:42:15 +0100 Subject: [PATCH 2/2] chore: dummy product description --- .../Factory/PhpDocResourceMetadataCollectionFactory.php | 4 ++-- tests/Fixtures/TestBundle/Document/DummyProduct.php | 2 +- tests/Fixtures/TestBundle/Entity/DummyProduct.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php b/src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php index 38c69a63deb..b7c1378b57b 100644 --- a/src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php +++ b/src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php @@ -64,8 +64,8 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn $phpDocParser = new PhpDocParser($config, new TypeParser($config, new ConstExprParser($config)), new ConstExprParser($config)); $lexer = new Lexer($config); } elseif (class_exists(PhpDocParser::class)) { - $phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser()); - $lexer = new Lexer(); + $phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser()); // @phpstan-ignore-line + $lexer = new Lexer(); // @phpstan-ignore-line } $this->phpDocParser = $phpDocParser; $this->lexer = $lexer; diff --git a/tests/Fixtures/TestBundle/Document/DummyProduct.php b/tests/Fixtures/TestBundle/Document/DummyProduct.php index 0887236029b..cdd001ca68f 100644 --- a/tests/Fixtures/TestBundle/Document/DummyProduct.php +++ b/tests/Fixtures/TestBundle/Document/DummyProduct.php @@ -23,7 +23,7 @@ /** * Dummy Product. * - * https://github.com/api-platform/core/issues/1107. + * @see https://github.com/api-platform/core/issues/1107 * * @author Antoine Bluchet */ diff --git a/tests/Fixtures/TestBundle/Entity/DummyProduct.php b/tests/Fixtures/TestBundle/Entity/DummyProduct.php index 0f34fe8174d..d6e428f8a02 100644 --- a/tests/Fixtures/TestBundle/Entity/DummyProduct.php +++ b/tests/Fixtures/TestBundle/Entity/DummyProduct.php @@ -23,7 +23,7 @@ /** * Dummy Product. * - * https://github.com/api-platform/core/issues/1107. + * @see https://github.com/api-platform/core/issues/1107 * * @author Antoine Bluchet */