Skip to content

Commit bba0306

Browse files
xabbuhsoyuka
andauthored
fix: properly support phpstan/phpdoc-parser 2 (#6789)
Co-authored-by: soyuka <[email protected]>
1 parent 17c916c commit bba0306

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
"justinrainbow/json-schema": "^5.2.1",
151151
"phpspec/prophecy-phpunit": "^2.0",
152152
"phpstan/extension-installer": "^1.1",
153-
"phpstan/phpdoc-parser": "^1.13",
153+
"phpstan/phpdoc-parser": "^1.13|^2.0",
154154
"phpstan/phpstan": "^1.10",
155155
"phpstan/phpstan-doctrine": "^1.0",
156156
"phpstan/phpstan-phpunit": "^1.0",

src/Metadata/Resource/Factory/PhpDocResourceMetadataCollectionFactory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use PHPStan\PhpDocParser\Parser\PhpDocParser;
2626
use PHPStan\PhpDocParser\Parser\TokenIterator;
2727
use PHPStan\PhpDocParser\Parser\TypeParser;
28+
use PHPStan\PhpDocParser\ParserConfig;
2829

2930
/**
3031
* Extracts descriptions from PHPDoc.
@@ -58,9 +59,13 @@ public function __construct(private readonly ResourceMetadataCollectionFactoryIn
5859
}
5960
$phpDocParser = null;
6061
$lexer = null;
61-
if (class_exists(PhpDocParser::class)) {
62-
$phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser());
63-
$lexer = new Lexer();
62+
if (class_exists(PhpDocParser::class) && class_exists(ParserConfig::class)) {
63+
$config = new ParserConfig([]);
64+
$phpDocParser = new PhpDocParser($config, new TypeParser($config, new ConstExprParser($config)), new ConstExprParser($config));
65+
$lexer = new Lexer($config);
66+
} elseif (class_exists(PhpDocParser::class)) {
67+
$phpDocParser = new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser()); // @phpstan-ignore-line
68+
$lexer = new Lexer(); // @phpstan-ignore-line
6469
}
6570
$this->phpDocParser = $phpDocParser;
6671
$this->lexer = $lexer;

tests/Fixtures/TestBundle/Document/DummyProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Dummy Product.
2525
*
26-
* https://github.com/api-platform/core/issues/1107.
26+
* @see https://github.com/api-platform/core/issues/1107
2727
*
2828
* @author Antoine Bluchet <[email protected]>
2929
*/

tests/Fixtures/TestBundle/Entity/DummyProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Dummy Product.
2525
*
26-
* https://github.com/api-platform/core/issues/1107.
26+
* @see https://github.com/api-platform/core/issues/1107
2727
*
2828
* @author Antoine Bluchet <[email protected]>
2929
*/

0 commit comments

Comments
 (0)