Configure parser classes using ParserConfig
2.3.xIn version 2.0, parser classes (like Lexer, ConstExprParser, TypeParser, and PhpDocParser) share a common ParserConfig object. This ensures consistent configuration across the parser components and allows for future optional parameters without breaking constructor signatures.
Instead of passing multiple boolean values and attribute arrays to each constructor, instantiate a ParserConfig and pass it to all parser components.
use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\ParserConfig;
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
$config = new ParserConfig(usedAttributes: ['lines' => true, 'indexes' => true]);
$lexer = new Lexer($config);
$constExprParser = new ConstExprParser($config);
$typeParser = new TypeParser($config, $constExprParser);
$phpDocParser = new PhpDocParser($config, $typeParser, $constExprParser);