Skip to content

[Serializer][TypeInfo] fix support for phpstan/phpdoc-parser 2 #58804

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

Merged
merged 1 commit into from
Nov 7, 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 src/Symfony/Component/Serializer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"require-dev": {
"phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0",
"phpstan/phpdoc-parser": "^1.0",
"phpstan/phpdoc-parser": "^1.0|^2.0",
"seld/jsonlint": "^1.10",
"symfony/cache": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use Symfony\Component\TypeInfo\Exception\RuntimeException;
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
use Symfony\Component\TypeInfo\Type;
Expand Down Expand Up @@ -157,8 +158,14 @@
return [];
}

$this->phpstanLexer ??= new Lexer();
$this->phpstanParser ??= new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser());
if (class_exists(ParserConfig::class)) {
$config = new ParserConfig([]);
$this->phpstanLexer ??= new Lexer($config);
$this->phpstanParser ??= new PhpDocParser($config, new TypeParser($config, new ConstExprParser($config)), new ConstExprParser($config));

Check failure on line 164 in src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php:164:64: InvalidArgument: Argument 2 of PHPStan\PhpDocParser\Parser\PhpDocParser::__construct expects PHPStan\PhpDocParser\Parser\ConstExprParser, but PHPStan\PhpDocParser\Parser\TypeParser provided (see https://psalm.dev/004)

Check failure on line 164 in src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php:164:88: InvalidArgument: Argument 2 of PHPStan\PhpDocParser\Parser\TypeParser::__construct expects bool, but PHPStan\PhpDocParser\Parser\ConstExprParser provided (see https://psalm.dev/004)

Check failure on line 164 in src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php:164:119: InvalidArgument: Argument 3 of PHPStan\PhpDocParser\Parser\PhpDocParser::__construct expects bool, but PHPStan\PhpDocParser\Parser\ConstExprParser provided (see https://psalm.dev/004)

Check failure on line 164 in src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php:164:139: InvalidArgument: Argument 1 of PHPStan\PhpDocParser\Parser\ConstExprParser::__construct expects bool, but PHPStan\PhpDocParser\Parser\ConstExprParser|null provided (see https://psalm.dev/004)

Check failure on line 164 in src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php:164:64: InvalidArgument: Argument 2 of PHPStan\PhpDocParser\Parser\PhpDocParser::__construct expects PHPStan\PhpDocParser\Parser\ConstExprParser, but PHPStan\PhpDocParser\Parser\TypeParser provided (see https://psalm.dev/004)

Check failure on line 164 in src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php:164:88: InvalidArgument: Argument 2 of PHPStan\PhpDocParser\Parser\TypeParser::__construct expects bool, but PHPStan\PhpDocParser\Parser\ConstExprParser provided (see https://psalm.dev/004)

Check failure on line 164 in src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php:164:119: InvalidArgument: Argument 3 of PHPStan\PhpDocParser\Parser\PhpDocParser::__construct expects bool, but PHPStan\PhpDocParser\Parser\ConstExprParser provided (see https://psalm.dev/004)

Check failure on line 164 in src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php:164:139: InvalidArgument: Argument 1 of PHPStan\PhpDocParser\Parser\ConstExprParser::__construct expects bool, but PHPStan\PhpDocParser\Parser\ConstExprParser|null provided (see https://psalm.dev/004)
} else {
$this->phpstanLexer ??= new Lexer();
$this->phpstanParser ??= new PhpDocParser(new TypeParser(new ConstExprParser()), new ConstExprParser());
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use Symfony\Component\TypeInfo\Exception\InvalidArgumentException;
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
use Symfony\Component\TypeInfo\Type;
Expand Down Expand Up @@ -63,8 +64,14 @@

public function __construct()
{
$this->lexer = new Lexer();
$this->parser = new TypeParser(new ConstExprParser());
if (class_exists(ParserConfig::class)) {
$config = new ParserConfig([]);
$this->lexer = new Lexer($config);
$this->parser = new TypeParser($config, new ConstExprParser($config));

Check failure on line 70 in src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php:70:44: InvalidArgument: Argument 1 of PHPStan\PhpDocParser\Parser\TypeParser::__construct expects PHPStan\PhpDocParser\Parser\ConstExprParser|null, but bool provided (see https://psalm.dev/004)

Check failure on line 70 in src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php:70:53: InvalidArgument: Argument 2 of PHPStan\PhpDocParser\Parser\TypeParser::__construct expects bool, but PHPStan\PhpDocParser\Parser\ConstExprParser provided (see https://psalm.dev/004)
} else {
$this->lexer = new Lexer();
$this->parser = new TypeParser(new ConstExprParser());
}
}

public function resolve(mixed $subject, ?TypeContext $typeContext = null): Type
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/TypeInfo/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"psr/container": "^1.1|^2.0"
},
"require-dev": {
"phpstan/phpdoc-parser": "^1.0",
"phpstan/phpdoc-parser": "^1.0|^2.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/property-info": "^6.4|^7.0"
},
Expand Down