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 0c70d2c commit aea9739
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"webmozart/assert": "^1.9.1",
"phpdocumentor/reflection-common": "^2.2",
"ext-filter": "*",
"phpstan/phpdoc-parser": "^1.7",
"phpstan/phpdoc-parser": "^1.7|^2.0",
"doctrine/deprecations": "^1.1"
},
"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.

32 changes: 22 additions & 10 deletions src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use RuntimeException;

use function ltrim;
Expand All @@ -44,16 +45,27 @@ class AbstractPHPStanFactory implements Factory

public function __construct(PHPStanFactory ...$factories)
{
$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
);
if (class_exists(ParserConfig::class)) {
$config = new ParserConfig(['indexes' => true, 'lines' => true]);
$this->lexer = new Lexer($config);

Check failure on line 50 in src/DocBlock/Tags/Factory/AbstractPHPStanFactory.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.
$constParser = new ConstExprParser($config);

Check failure on line 51 in src/DocBlock/Tags/Factory/AbstractPHPStanFactory.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.
$this->parser = new PhpDocParser(
$config,

Check failure on line 53 in src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php

View workflow job for this annotation

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

Parameter #1 $typeParser of class PHPStan\PhpDocParser\Parser\PhpDocParser constructor expects PHPStan\PhpDocParser\Parser\TypeParser, PHPStan\PhpDocParser\ParserConfig given.
new TypeParser($config, $constParser),

Check failure on line 54 in src/DocBlock/Tags/Factory/AbstractPHPStanFactory.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 54 in src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php

View workflow job for this annotation

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

Parameter #2 $constantExprParser of class PHPStan\PhpDocParser\Parser\PhpDocParser constructor expects PHPStan\PhpDocParser\Parser\ConstExprParser, PHPStan\PhpDocParser\Parser\TypeParser given.

Check failure on line 54 in src/DocBlock/Tags/Factory/AbstractPHPStanFactory.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.
$constParser

Check failure on line 55 in src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php

View workflow job for this annotation

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

Parameter #3 $requireWhitespaceBeforeDescription of class PHPStan\PhpDocParser\Parser\PhpDocParser constructor expects bool, PHPStan\PhpDocParser\Parser\ConstExprParser given.
);
} 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;
}

Expand Down
16 changes: 12 additions & 4 deletions tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use PHPUnit\Framework\TestCase;

use function property_exists;
Expand All @@ -32,11 +33,18 @@ abstract class TagFactoryTestCase extends TestCase
{
public function parseTag(string $tag): PhpDocTagNode
{
$lexer = new Lexer();
$tokens = $lexer->tokenize($tag);
$constParser = new ConstExprParser();
if (class_exists(ParserConfig::class)) {
$config = new ParserConfig([]);
$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) {
$tagNode->value->setAttribute('description', $tagNode->value->description);
}
Expand Down

0 comments on commit aea9739

Please sign in to comment.