2727
2828class NameResolver extends NodeVisitorAbstract
2929{
30- /** @var NameContext Naming context */
3130 protected NameContext $ nameContext ;
3231
33- /** @var bool Whether to preserve original names */
3432 protected bool $ preserveOriginalNames ;
3533
36- /** @var bool Whether to replace resolved nodes in place, or to add resolvedNode attributes */
3734 protected bool $ replaceNodes ;
3835
39- /** @var bool Whether to parse DocBlock Custom Annotations */
40- protected $ parseCustomAnnotations ;
36+ protected bool $ parseCustomAnnotations ;
4137
42- /** @var PhpDocParser */
43- protected $ phpDocParser ;
38+ protected PhpDocParser $ phpDocParser ;
4439
45- /** @var Lexer */
46- protected $ phpDocLexer ;
40+ protected Lexer $ phpDocLexer ;
4741
4842 /**
4943 * Constructs a name resolution visitor.
@@ -58,6 +52,9 @@ class NameResolver extends NodeVisitorAbstract
5852 *
5953 * @param ErrorHandler|null $errorHandler Error handler
6054 * @param array{preserveOriginalNames?: bool, replaceNodes?: bool, parseCustomAnnotations?: bool} $options Options
55+ *
56+ * @psalm-suppress TooFewArguments
57+ * @psalm-suppress InvalidArgument
6158 */
6259 public function __construct (?ErrorHandler $ errorHandler = null , array $ options = [])
6360 {
@@ -66,11 +63,19 @@ public function __construct(?ErrorHandler $errorHandler = null, array $options =
6663 $ this ->replaceNodes = $ options ['replaceNodes ' ] ?? true ;
6764 $ this ->parseCustomAnnotations = $ options ['parseCustomAnnotations ' ] ?? true ;
6865
69- $ parserConfig = new ParserConfig ([]);
70- $ constExprParser = new ConstExprParser ($ parserConfig );
71- $ typeParser = new TypeParser ($ parserConfig , $ constExprParser );
72- $ this ->phpDocParser = new PhpDocParser ($ parserConfig , $ typeParser , $ constExprParser );
73- $ this ->phpDocLexer = new Lexer ($ parserConfig );
66+ // this if is to allow using v 1.2 or v2
67+ if (class_exists (ParserConfig::class)) {
68+ $ parserConfig = new ParserConfig ([]);
69+ $ constExprParser = new ConstExprParser ($ parserConfig );
70+ $ typeParser = new TypeParser ($ parserConfig , $ constExprParser );
71+ $ this ->phpDocParser = new PhpDocParser ($ parserConfig , $ typeParser , $ constExprParser );
72+ $ this ->phpDocLexer = new Lexer ($ parserConfig );
73+ } else {
74+ $ typeParser = new TypeParser ();
75+ $ constExprParser = new ConstExprParser ();
76+ $ this ->phpDocParser = new PhpDocParser ($ typeParser , $ constExprParser );
77+ $ this ->phpDocLexer = new Lexer ();
78+ }
7479 }
7580
7681 /**
0 commit comments