Merge pull request #386 from xabbuh/phpstan-phpdoc-parser-2

add support for phpstan/phpdoc-parser 2
This commit is contained in:
Jaap van Otterdijk
2024-11-12 12:21:26 +01:00
committed by GitHub
7 changed files with 75 additions and 17 deletions
+2 -1
View File
@@ -2,7 +2,8 @@
"symbol-whitelist" : [ "symbol-whitelist" : [
"null", "true", "false", "null", "true", "false",
"static", "self", "parent", "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"
], ],
"php-core-extensions" : [ "php-core-extensions" : [
"Core", "Core",
+1 -1
View File
@@ -19,7 +19,7 @@
"webmozart/assert": "^1.9.1", "webmozart/assert": "^1.9.1",
"phpdocumentor/reflection-common": "^2.2", "phpdocumentor/reflection-common": "^2.2",
"ext-filter": "*", "ext-filter": "*",
"phpstan/phpdoc-parser": "^1.7", "phpstan/phpdoc-parser": "^1.7|^2.0",
"doctrine/deprecations": "^1.1" "doctrine/deprecations": "^1.1"
}, },
"require-dev": { "require-dev": {
Generated
+1 -1
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "8d0008447edbcdb6139a9c64654e5931", "content-hash": "7980f2ec05f5b526fd14283b3ff34b2a",
"packages": [ "packages": [
{ {
"name": "doctrine/deprecations", "name": "doctrine/deprecations",
+28
View File
@@ -3,5 +3,33 @@ parameters:
ignoreErrors: ignoreErrors:
- '#Method phpDocumentor\\Reflection\\DocBlock\\StandardTagFactory::createTag\(\) should return phpDocumentor\\Reflection\\DocBlock\\Tag but returns mixed#' - '#Method phpDocumentor\\Reflection\\DocBlock\\StandardTagFactory::createTag\(\) should return phpDocumentor\\Reflection\\DocBlock\\Tag but returns mixed#'
- '#Offset 2 on array\{string, 28, int\} on left side of \?\? always exists and is not nullable\.#' - '#Offset 2 on array\{string, 28, int\} on left side of \?\? always exists and is not nullable\.#'
-
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/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
-
message: "#^Parameter \\#1 \\$parseDoctrineAnnotations of class PHPStan\\\\PhpDocParser\\\\Lexer\\\\Lexer constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
-
message: "#^Parameter \\#1 \\$typeParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
-
message: "#^Parameter \\#1 \\$unescapeStrings of class PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
count: 1
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
-
message: "#^Parameter \\#2 \\$constantExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser, PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser given\\.$#"
count: 1
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
-
message: "#^Parameter \\#2 \\$quoteAwareConstExprString of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#"
count: 1
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
-
message: "#^Parameter \\#3 \\$requireWhitespaceBeforeDescription of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#"
count: 1
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
paths: paths:
- src - src
+7
View File
@@ -68,5 +68,12 @@
<file name="src/Utils.php"/> <file name="src/Utils.php"/>
</errorLevel> </errorLevel>
</ArgumentTypeCoercion> </ArgumentTypeCoercion>
<InvalidArgument>
<errorLevel type="suppress">
<referencedFunction name="PHPStan\PhpDocParser\Parser\PhpDocParser::__construct"/>
<referencedFunction name="PHPStan\PhpDocParser\Parser\TypeParser::__construct"/>
</errorLevel>
</InvalidArgument>
</issueHandlers> </issueHandlers>
</psalm> </psalm>
@@ -21,8 +21,10 @@ use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator; use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser; use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use RuntimeException; use RuntimeException;
use function class_exists;
use function ltrim; use function ltrim;
use function property_exists; use function property_exists;
use function rtrim; use function rtrim;
@@ -44,16 +46,27 @@ class AbstractPHPStanFactory implements Factory
public function __construct(PHPStanFactory ...$factories) public function __construct(PHPStanFactory ...$factories)
{ {
$this->lexer = new Lexer(true); if (class_exists(ParserConfig::class)) {
$constParser = new ConstExprParser(true, true, ['lines' => true, 'indexes' => true]); $config = new ParserConfig(['indexes' => true, 'lines' => true]);
$this->parser = new PhpDocParser( $this->lexer = new Lexer($config);
new TypeParser($constParser, true, ['lines' => true, 'indexes' => true]), $constParser = new ConstExprParser($config);
$constParser, $this->parser = new PhpDocParser(
true, $config,
true, new TypeParser($config, $constParser),
['lines' => true, 'indexes' => true], $constParser
true );
); } else {
$this->lexer = new Lexer(true);
$constParser = new ConstExprParser(true, true, ['lines' => true, 'indexes' => true]);
$this->parser = new PhpDocParser(
new TypeParser($constParser, true, ['lines' => true, 'indexes' => true]),
$constParser,
true,
true,
['lines' => true, 'indexes' => true],
true
);
}
$this->factories = $factories; $this->factories = $factories;
} }
@@ -24,19 +24,28 @@ use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator; use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser; use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use function class_exists;
use function property_exists; use function property_exists;
abstract class TagFactoryTestCase extends TestCase abstract class TagFactoryTestCase extends TestCase
{ {
public function parseTag(string $tag): PhpDocTagNode public function parseTag(string $tag): PhpDocTagNode
{ {
$lexer = new Lexer(); if (class_exists(ParserConfig::class)) {
$tokens = $lexer->tokenize($tag); $config = new ParserConfig([]);
$constParser = new ConstExprParser(); $lexer = new Lexer($config);
$constParser = new ConstExprParser($config);
$phpDocParser = new PhpDocParser($config, new TypeParser($config, $constParser), $constParser);
} else {
$lexer = new Lexer();
$constParser = new ConstExprParser();
$phpDocParser = new PhpDocParser(new TypeParser($constParser), $constParser);
}
$tagNode = (new PhpDocParser(new TypeParser($constParser), $constParser))->parseTag(new TokenIterator($tokens)); $tagNode = ($phpDocParser)->parseTag(new TokenIterator($lexer->tokenize($tag)));
if (property_exists($tagNode->value, 'description') === true) { if (property_exists($tagNode->value, 'description') === true) {
$tagNode->value->setAttribute('description', $tagNode->value->description); $tagNode->value->setAttribute('description', $tagNode->value->description);
} }