Skip to content

Commit 4de1d3c

Browse files
committed
Allow PHPStan PHPDoc parser 2.0
1 parent a093b21 commit 4de1d3c

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"doctrine/instantiator": "^1.3.1 || ^2.0",
2727
"doctrine/lexer": "^2.0 || ^3.0",
2828
"jms/metadata": "^2.6",
29-
"phpstan/phpdoc-parser": "^1.20"
29+
"phpstan/phpdoc-parser": "^1.20 || ^2.0"
3030
},
3131
"suggest": {
3232
"doctrine/collections": "Required if you like to use doctrine collection types as ArrayCollection.",
@@ -37,17 +37,18 @@
3737
"require-dev": {
3838
"ext-pdo_sqlite": "*",
3939
"doctrine/annotations": "^1.14 || ^2.0",
40+
"slevomat/coding-standard": "dev-master#f2cc4c553eae68772624ffd7dd99022343b69c31 as 8.11.9999",
4041
"doctrine/coding-standard": "^12.0",
4142
"doctrine/orm": "^2.14 || ^3.0",
4243
"doctrine/persistence": "^2.5.2 || ^3.0",
4344
"doctrine/phpcr-odm": "^1.5.2 || ^2.0",
4445
"jackalope/jackalope-doctrine-dbal": "^1.3",
4546
"ocramius/proxy-manager": "^1.0 || ^2.0",
4647
"phpbench/phpbench": "^1.0",
47-
"phpstan/phpstan": "^1.10.57",
48+
"phpstan/phpstan": "^2.0",
4849
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.0",
4950
"psr/container": "^1.0 || ^2.0",
50-
"rector/rector": "^1.0.0",
51+
"rector/rector": "dev-main#49f448773bbd6b81a57de15a92f25519b241ea20 as 2.0",
5152
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
5253
"symfony/expression-language": "^5.4 || ^6.0 || ^7.0",
5354
"symfony/filesystem": "^5.4 || ^6.0 || ^7.0",

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ parameters:
2020
- '#^Property JMS\\Serializer\\Tests\\Fixtures\\DocBlockType\\Collection\\CollectionOfClassesWithFullNamespacePath\:\:\$productIds has unknown class JMS\\Serializer\\Tests\\Fixtures\\DocBlockType\\Collection\\JMS\\Serializer\\Tests\\Fixtures\\DocBlockType\\Collection\\Product as its type\.$#'
2121
- '#^Property JMS\\Serializer\\Tests\\Fixtures\\DocBlockType\\Collection\\CollectionOfInterfacesWithFullNamespacePath\:\:\$productColors has unknown class JMS\\Serializer\\Tests\\Fixtures\\DocBlockType\\Collection\\JMS\\Serializer\\Tests\\Fixtures\\DocBlockType\\Collection\\Details\\ProductColor as its type\.$#'
2222
- '#^Method JMS\\Serializer\\GraphNavigator\\DeserializationGraphNavigator\:\:resolveMetadata\(\) should return JMS\\Serializer\\Metadata\\ClassMetadata\|null#'
23+
- '#^ArrayObject<\*NEVER\*, \*NEVER\*> does not accept list<string\|null>\.#'
24+
- '#^ArrayObject<\*NEVER\*, \*NEVER\*> does not accept array<string, ArrayObject>\.#'
2325
paths:
2426
- %currentWorkingDirectory%/src
2527
- %currentWorkingDirectory%/tests

phpstan/no-typed-prop.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ parameters:
88
- %currentWorkingDirectory%/tests/Fixtures/DocBlockType/Collection/ConstructorPropertyPromotion.php
99
- %currentWorkingDirectory%/tests/Fixtures/DocBlockType/Collection/ConstructorPropertyPromotionWithoutDocblock.php
1010
- %currentWorkingDirectory%/tests/Fixtures/DocBlockType/Collection/ConstructorPropertyPromotionWithScalar.php
11-
- %currentWorkingDirectory%/tests/Serializer/BaseSerializationTest.php

phpstan/no-unions.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
parameters:
22
excludePaths:
3+
- %currentWorkingDirectory%/src/Handler/UnionHandler.php
34
- %currentWorkingDirectory%/tests/Fixtures/TypedProperties/ComplexDiscriminatedUnion.php

src/Handler/FormErrorHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ private function getErrorMessage(FormError $error): ?string
129129

130130
private function convertFormToArray(SerializationVisitorInterface $visitor, FormInterface $data): \ArrayObject
131131
{
132-
/** @var \ArrayObject{errors?:array<string>,children?:array<string,\ArrayObject>} $form */
133132
$form = new \ArrayObject();
134133
$errors = [];
135134
foreach ($data->getErrors() as $error) {

src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PHPStan\PhpDocParser\Parser\PhpDocParser;
2121
use PHPStan\PhpDocParser\Parser\TokenIterator;
2222
use PHPStan\PhpDocParser\Parser\TypeParser;
23+
use PHPStan\PhpDocParser\ParserConfig;
2324

2425
/**
2526
* @internal
@@ -47,11 +48,25 @@ final class DocBlockTypeResolver
4748

4849
public function __construct()
4950
{
50-
$constExprParser = new ConstExprParser();
51-
$typeParser = new TypeParser($constExprParser);
51+
// PHPStan PHPDoc Parser 2
52+
if (class_exists(ParserConfig::class)) {
53+
$config = new ParserConfig(['lines' => true, 'indexes' => true]);
5254

53-
$this->phpDocParser = new PhpDocParser($typeParser, $constExprParser);
54-
$this->lexer = new Lexer();
55+
$constExprParser = new ConstExprParser($config);
56+
$typeParser = new TypeParser($config, $constExprParser);
57+
58+
$this->phpDocParser = new PhpDocParser($config, $typeParser, $constExprParser);
59+
$this->lexer = new Lexer($config);
60+
} else {
61+
// @phpstan-ignore arguments.count
62+
$constExprParser = new ConstExprParser();
63+
// @phpstan-ignore arguments.count
64+
$typeParser = new TypeParser($constExprParser);
65+
// @phpstan-ignore arguments.count
66+
$this->phpDocParser = new PhpDocParser($typeParser, $constExprParser);
67+
// @phpstan-ignore arguments.count
68+
$this->lexer = new Lexer();
69+
}
5570
}
5671

5772
/**

0 commit comments

Comments
 (0)