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 support for phpstan/phpdoc-parser 2 #212

Merged
merged 1 commit into from
Nov 9, 2024
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-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