Skip to content

Commit

Permalink
support also current stable pre-2.0 phpdoc-parser
Browse files Browse the repository at this point in the history
[closes #689]
  • Loading branch information
hrach committed Oct 30, 2024
1 parent 844795b commit caca579
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"nette/caching": "~3.2 || ~3.1.3",
"nette/utils": "~3.0 || ~4.0",
"nextras/dbal": "dev-main",
"phpstan/phpdoc-parser": "2.0.x-dev"
"phpstan/phpdoc-parser": "^1.33.0 || 2.0.x-dev"
},
"require-dev": {
"doctrine/sql-formatter": "^1.5.1",
Expand All @@ -41,7 +41,7 @@
"phpstan/phpstan-mockery": "1.1.2",
"phpstan/phpstan-strict-rules": "1.5.2",
"nextras/multi-query-parser": "~1.0",
"nextras/orm-phpstan": "~1.0@dev",
"nextras/orm-phpstan": "^1.0.1",
"tracy/tracy": "~2.3"
},
"autoload": {
Expand Down
18 changes: 13 additions & 5 deletions src/Entity/Reflection/MetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ public function __construct(array $entityClassesMap)
$this->entityClassesMap = $entityClassesMap;
$this->modifierParser = new ModifierParser();

$config = new ParserConfig(usedAttributes: []);
$this->phpDocLexer = new Lexer($config);
$constExprParser = new ConstExprParser($config);
$typeParser = new TypeParser($config, $constExprParser);
$this->phpDocParser = new PhpDocParser($config, $typeParser, $constExprParser);
// phpdoc-parser 2.0
if (class_exists('PHPStan\PhpDocParser\ParserConfig')) {
$config = new ParserConfig(usedAttributes: []); // @phpstan-ignore-line
$this->phpDocLexer = new Lexer($config); // @phpstan-ignore-line
$constExprParser = new ConstExprParser($config); // @phpstan-ignore-line
$typeParser = new TypeParser($config, $constExprParser); // @phpstan-ignore-line
$this->phpDocParser = new PhpDocParser($config, $typeParser, $constExprParser); // @phpstan-ignore-line
} else {
$this->phpDocLexer = new Lexer(); // @phpstan-ignore-line
$constExprParser = new ConstExprParser(); // @phpstan-ignore-line
$typeParser = new TypeParser($constExprParser); // @phpstan-ignore-line
$this->phpDocParser = new PhpDocParser($typeParser, $constExprParser); // @phpstan-ignore-line
}
}


Expand Down

0 comments on commit caca579

Please sign in to comment.