Skip to content

Commit f0223a2

Browse files
committed
bug symfony#58804 [Serializer][TypeInfo] fix support for phpstan/phpdoc-parser 2 (xabbuh)
This PR was merged into the 7.1 branch. Discussion ---------- [Serializer][TypeInfo] fix support for phpstan/phpdoc-parser 2 | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | related to symfony#58796 | License | MIT Commits ------- ecb34a7 fix support for phpstan/phpdoc-parser 2
2 parents 1d88940 + ecb34a7 commit f0223a2

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/Symfony/Component/Serializer/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"require-dev": {
2424
"phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0",
25-
"phpstan/phpdoc-parser": "^1.0",
25+
"phpstan/phpdoc-parser": "^1.0|^2.0",
2626
"seld/jsonlint": "^1.10",
2727
"symfony/cache": "^6.4|^7.0",
2828
"symfony/config": "^6.4|^7.0",

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PHPStan\PhpDocParser\Parser\PhpDocParser;
1818
use PHPStan\PhpDocParser\Parser\TokenIterator;
1919
use PHPStan\PhpDocParser\Parser\TypeParser;
20+
use PHPStan\PhpDocParser\ParserConfig;
2021
use Symfony\Component\TypeInfo\Exception\RuntimeException;
2122
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
2223
use Symfony\Component\TypeInfo\Type;
@@ -157,8 +158,14 @@ private function collectTemplates(\ReflectionClass|\ReflectionFunctionAbstract $
157158
return [];
158159
}
159160

160-
$this->phpstanLexer ??= new Lexer();
161-
$this->phpstanParser ??= new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser());
161+
if (class_exists(ParserConfig::class)) {
162+
$config = new ParserConfig([]);
163+
$this->phpstanLexer ??= new Lexer($config);
164+
$this->phpstanParser ??= new PhpDocParser($config, new TypeParser($config, new ConstExprParser($config)), new ConstExprParser($config));
165+
} else {
166+
$this->phpstanLexer ??= new Lexer();
167+
$this->phpstanParser ??= new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser());
168+
}
162169

163170
$tokens = new TokenIterator($this->phpstanLexer->tokenize($rawDocNode));
164171

src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use PHPStan\PhpDocParser\Parser\ConstExprParser;
3535
use PHPStan\PhpDocParser\Parser\TokenIterator;
3636
use PHPStan\PhpDocParser\Parser\TypeParser;
37+
use PHPStan\PhpDocParser\ParserConfig;
3738
use Symfony\Component\TypeInfo\Exception\InvalidArgumentException;
3839
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
3940
use Symfony\Component\TypeInfo\Type;
@@ -63,8 +64,14 @@ final class StringTypeResolver implements TypeResolverInterface
6364

6465
public function __construct()
6566
{
66-
$this->lexer = new Lexer();
67-
$this->parser = new TypeParser(new ConstExprParser());
67+
if (class_exists(ParserConfig::class)) {
68+
$config = new ParserConfig([]);
69+
$this->lexer = new Lexer($config);
70+
$this->parser = new TypeParser($config, new ConstExprParser($config));
71+
} else {
72+
$this->lexer = new Lexer();
73+
$this->parser = new TypeParser(new ConstExprParser());
74+
}
6875
}
6976

7077
public function resolve(mixed $subject, ?TypeContext $typeContext = null): Type

src/Symfony/Component/TypeInfo/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"psr/container": "^1.1|^2.0"
3030
},
3131
"require-dev": {
32-
"phpstan/phpdoc-parser": "^1.0",
32+
"phpstan/phpdoc-parser": "^1.0|^2.0",
3333
"symfony/dependency-injection": "^6.4|^7.0",
3434
"symfony/property-info": "^6.4|^7.0"
3535
},

0 commit comments

Comments
 (0)