Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with phpstan/phpdoc-parser v2 #442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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": "~4",
"webmozart/assert": "^1.9",
"ext-json": "*",
"phpstan/phpdoc-parser": "^1.2",
"phpstan/phpdoc-parser": "^1.2|^2.0",
"ondram/ci-detector": "^4.1"
},
"require-dev": {
Expand Down
20 changes: 16 additions & 4 deletions src/Analyzer/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;

class NameResolver extends NodeVisitorAbstract
{
Expand Down Expand Up @@ -55,6 +56,9 @@ class NameResolver extends NodeVisitorAbstract
* namespacedName attribute, as usual.)
* * parseCustomAnnotations (default true): Whether to parse DocBlock Custom Annotations.
*
* @psalm-suppress TooFewArguments
* @psalm-suppress InvalidArgument
*
* @param ErrorHandler|null $errorHandler Error handler
* @param array $options Options
*/
Expand All @@ -65,10 +69,18 @@ public function __construct(?ErrorHandler $errorHandler = null, array $options =
$this->replaceNodes = $options['replaceNodes'] ?? true;
$this->parseCustomAnnotations = $options['parseCustomAnnotations'] ?? true;

$typeParser = new TypeParser();
$constExprParser = new ConstExprParser();
$this->phpDocParser = new PhpDocParser($typeParser, $constExprParser);
$this->phpDocLexer = new Lexer();
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();
}
}

/**
Expand Down
Loading