27
27
28
28
class NameResolver extends NodeVisitorAbstract
29
29
{
30
- /** @var NameContext Naming context */
31
30
protected NameContext $ nameContext ;
32
31
33
- /** @var bool Whether to preserve original names */
34
32
protected bool $ preserveOriginalNames ;
35
33
36
- /** @var bool Whether to replace resolved nodes in place, or to add resolvedNode attributes */
37
34
protected bool $ replaceNodes ;
38
35
39
- /** @var bool Whether to parse DocBlock Custom Annotations */
40
- protected $ parseCustomAnnotations ;
36
+ protected bool $ parseCustomAnnotations ;
41
37
42
- /** @var PhpDocParser */
43
- protected $ phpDocParser ;
38
+ protected PhpDocParser $ phpDocParser ;
44
39
45
- /** @var Lexer */
46
- protected $ phpDocLexer ;
40
+ protected Lexer $ phpDocLexer ;
47
41
48
42
/**
49
43
* Constructs a name resolution visitor.
@@ -58,6 +52,9 @@ class NameResolver extends NodeVisitorAbstract
58
52
*
59
53
* @param ErrorHandler|null $errorHandler Error handler
60
54
* @param array{preserveOriginalNames?: bool, replaceNodes?: bool, parseCustomAnnotations?: bool} $options Options
55
+ *
56
+ * @psalm-suppress TooFewArguments
57
+ * @psalm-suppress InvalidArgument
61
58
*/
62
59
public function __construct (?ErrorHandler $ errorHandler = null , array $ options = [])
63
60
{
@@ -66,11 +63,19 @@ public function __construct(?ErrorHandler $errorHandler = null, array $options =
66
63
$ this ->replaceNodes = $ options ['replaceNodes ' ] ?? true ;
67
64
$ this ->parseCustomAnnotations = $ options ['parseCustomAnnotations ' ] ?? true ;
68
65
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
+ }
74
79
}
75
80
76
81
/**
0 commit comments