add support for phpstan/phpdoc-parser 2

This commit is contained in:
Christian Flothmann
2024-11-10 22:44:37 +01:00
parent 0c70d2c566
commit 2a8b28d42a
7 changed files with 75 additions and 17 deletions
@@ -24,19 +24,28 @@ use PHPStan\PhpDocParser\Parser\ConstExprParser;
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();
$tokens = $lexer->tokenize($tag);
$constParser = new ConstExprParser();
if (class_exists(ParserConfig::class)) {
$config = new ParserConfig([]);
$lexer = new Lexer($config);
$constParser = new ConstExprParser($config);
$phpDocParser = new PhpDocParser($config, new TypeParser($config, $constParser), $constParser);
} else {
$lexer = new Lexer();
$constParser = new ConstExprParser();
$phpDocParser = new PhpDocParser(new TypeParser($constParser), $constParser);
}
$tagNode = (new PhpDocParser(new TypeParser($constParser), $constParser))->parseTag(new TokenIterator($tokens));
$tagNode = ($phpDocParser)->parseTag(new TokenIterator($lexer->tokenize($tag)));
if (property_exists($tagNode->value, 'description') === true) {
$tagNode->value->setAttribute('description', $tagNode->value->description);
}