Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"nikic/php-parser": "~5",
"webmozart/assert": "^1.9",
"ext-json": "*",
"phpstan/phpdoc-parser": "^2.0",
"phpstan/phpdoc-parser": "^1.2|^2.0",
"ondram/ci-detector": "^4.1"
},
"require-dev": {
Expand Down
33 changes: 19 additions & 14 deletions src/Analyzer/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,17 @@

class NameResolver extends NodeVisitorAbstract
{
/** @var NameContext Naming context */
protected NameContext $nameContext;

/** @var bool Whether to preserve original names */
protected bool $preserveOriginalNames;

/** @var bool Whether to replace resolved nodes in place, or to add resolvedNode attributes */
protected bool $replaceNodes;

/** @var bool Whether to parse DocBlock Custom Annotations */
protected $parseCustomAnnotations;
protected bool $parseCustomAnnotations;

/** @var PhpDocParser */
protected $phpDocParser;
protected PhpDocParser $phpDocParser;

/** @var Lexer */
protected $phpDocLexer;
protected Lexer $phpDocLexer;

/**
* Constructs a name resolution visitor.
Expand All @@ -58,6 +52,9 @@
*
* @param ErrorHandler|null $errorHandler Error handler
* @param array{preserveOriginalNames?: bool, replaceNodes?: bool, parseCustomAnnotations?: bool} $options Options
*
* @psalm-suppress TooFewArguments
* @psalm-suppress InvalidArgument
*/
public function __construct(?ErrorHandler $errorHandler = null, array $options = [])
{
Expand All @@ -66,11 +63,19 @@
$this->replaceNodes = $options['replaceNodes'] ?? true;
$this->parseCustomAnnotations = $options['parseCustomAnnotations'] ?? true;

$parserConfig = new ParserConfig([]);
$constExprParser = new ConstExprParser($parserConfig);
$typeParser = new TypeParser($parserConfig, $constExprParser);
$this->phpDocParser = new PhpDocParser($parserConfig, $typeParser, $constExprParser);
$this->phpDocLexer = new Lexer($parserConfig);
// this if is to allow using v 1.2 or v2
if (class_exists(ParserConfig::class)) {
$parserConfig = new ParserConfig([]);
$constExprParser = new ConstExprParser($parserConfig);
$typeParser = new TypeParser($parserConfig, $constExprParser);
$this->phpDocParser = new PhpDocParser($parserConfig, $typeParser, $constExprParser);
$this->phpDocLexer = new Lexer($parserConfig);
} else {
$typeParser = new TypeParser();
$constExprParser = new ConstExprParser();
$this->phpDocParser = new PhpDocParser($typeParser, $constExprParser);
$this->phpDocLexer = new Lexer();

Check warning on line 77 in src/Analyzer/NameResolver.php

View check run for this annotation

Codecov / codecov/patch

src/Analyzer/NameResolver.php#L74-L77

Added lines #L74 - L77 were not covered by tests
}
}

/**
Expand Down