Skip to content

Commit

Permalink
add support for phpstan/phpdoc-parser 2
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Nov 7, 2024
1 parent 1fb5ba8 commit 6e28db3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": "^7.3 || ^8.0",
"phpdocumentor/reflection-common": "^2.0",
"phpstan/phpdoc-parser": "^1.18",
"phpstan/phpdoc-parser": "^1.18|^2.0",
"doctrine/deprecations": "^1.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
use PHPStan\PhpDocParser\Parser\ParserException;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use RuntimeException;

use function array_filter;
Expand Down Expand Up @@ -189,8 +190,15 @@ final class TypeResolver
public function __construct(?FqsenResolver $fqsenResolver = null)
{
$this->fqsenResolver = $fqsenResolver ?: new FqsenResolver();
$this->typeParser = new TypeParser(new ConstExprParser());
$this->lexer = new Lexer();

if (class_exists(ParserConfig::class)) {
$parserConfig = new ParserConfig([]);
$this->typeParser = new TypeParser($parserConfig, new ConstExprParser($parserConfig));

Check failure on line 196 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Parameter #1 $constExprParser of class PHPStan\PhpDocParser\Parser\TypeParser constructor expects PHPStan\PhpDocParser\Parser\ConstExprParser|null, PHPStan\PhpDocParser\ParserConfig given.

Check failure on line 196 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Parameter #1 $unescapeStrings of class PHPStan\PhpDocParser\Parser\ConstExprParser constructor expects bool, PHPStan\PhpDocParser\ParserConfig given.

Check failure on line 196 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Parameter #2 $quoteAwareConstExprString of class PHPStan\PhpDocParser\Parser\TypeParser constructor expects bool, PHPStan\PhpDocParser\Parser\ConstExprParser given.
$this->lexer = new Lexer($parserConfig);

Check failure on line 197 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Parameter #1 $parseDoctrineAnnotations of class PHPStan\PhpDocParser\Lexer\Lexer constructor expects bool, PHPStan\PhpDocParser\ParserConfig given.
} else {
$this->typeParser = new TypeParser(new ConstExprParser());
$this->lexer = new Lexer();
}
}

/**
Expand Down

0 comments on commit 6e28db3

Please sign in to comment.