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 8, 2024
1 parent 1fb5ba8 commit f421ef3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"symbol-whitelist" : [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "XSLTProcessor", "PHPStan\\PhpDocParser\\ParserConfig",
"T_NAME_QUALIFIED", "T_NAME_FULLY_QUALIFIED"
],
"php-core-extensions" : [
Expand Down
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.

17 changes: 17 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ parameters:
- tests/benchmark/Assets/*
paths:
- src
ignoreErrors:
-
message: "#^Parameter \\#1 \\$constExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser\\|null, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/TypeResolver.php
-
message: "#^Parameter \\#1 \\$parseDoctrineAnnotations of class PHPStan\\\\PhpDocParser\\\\Lexer\\\\Lexer constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/TypeResolver.php
-
message: "#^Parameter \\#1 \\$unescapeStrings of class PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/TypeResolver.php
-
message: "#^Parameter \\#2 \\$quoteAwareConstExprString of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#"
count: 1
path: src/TypeResolver.php
22 changes: 22 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,27 @@
<file name="src/TypeResolver.php"/>
</errorLevel>
</RedundantConditionGivenDocblockType>

<InvalidArgument>
<errorLevel type="suppress">
<referencedFunction name="PHPStan\PhpDocParser\Lexer\Lexer::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\ConstExprParser::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\TypeParser::__construct"/>
</errorLevel>
</InvalidArgument>

<UndefinedDocblockClass>
<errorLevel type="suppress">
<referencedClass name="PHPStan\PhpDocParser\ParserConfig"/>
</errorLevel>
</UndefinedDocblockClass>

<MixedArgument>
<errorLevel type="suppress">
<referencedFunction name="PHPStan\PhpDocParser\Lexer\Lexer::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\ConstExprParser::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\TypeParser::__construct"/>
</errorLevel>
</MixedArgument>
</issueHandlers>
</psalm>
11 changes: 9 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,14 @@ 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)) {
$this->typeParser = new TypeParser(new ParserConfig([]), new ConstExprParser(new ParserConfig([])));
$this->lexer = new Lexer(new ParserConfig([]));
} else {
$this->typeParser = new TypeParser(new ConstExprParser());
$this->lexer = new Lexer();
}
}

/**
Expand Down

0 comments on commit f421ef3

Please sign in to comment.