From 2380860bce0e4abbe7a2456d05121c7ee1c067f5 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Mon, 25 Nov 2024 09:18:57 +0100 Subject: [PATCH 1/3] Allow PHPStan PHPDoc parser 2.0 --- composer.json | 7 +++--- phpstan.neon.dist | 2 ++ phpstan/no-typed-prop.neon | 1 - phpstan/no-unions.neon | 1 + src/Handler/FormErrorHandler.php | 1 - .../DocBlockDriver/DocBlockTypeResolver.php | 23 +++++++++++++++---- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 08406fc41..dc0b74ca3 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "doctrine/instantiator": "^1.3.1 || ^2.0", "doctrine/lexer": "^2.0 || ^3.0", "jms/metadata": "^2.6", - "phpstan/phpdoc-parser": "^1.20" + "phpstan/phpdoc-parser": "^1.20 || ^2.0" }, "suggest": { "doctrine/collections": "Required if you like to use doctrine collection types as ArrayCollection.", @@ -37,6 +37,7 @@ "require-dev": { "ext-pdo_sqlite": "*", "doctrine/annotations": "^1.14 || ^2.0", + "slevomat/coding-standard": "dev-master#f2cc4c553eae68772624ffd7dd99022343b69c31 as 8.11.9999", "doctrine/coding-standard": "^12.0", "doctrine/orm": "^2.14 || ^3.0", "doctrine/persistence": "^2.5.2 || ^3.0", @@ -44,10 +45,10 @@ "jackalope/jackalope-doctrine-dbal": "^1.3", "ocramius/proxy-manager": "^1.0 || ^2.0", "phpbench/phpbench": "^1.0", - "phpstan/phpstan": "^1.10.57", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.0 || ^10.0 || ^11.0", "psr/container": "^1.0 || ^2.0", - "rector/rector": "^1.0.0", + "rector/rector": "dev-main#49f448773bbd6b81a57de15a92f25519b241ea20 as 2.0", "symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0", "symfony/expression-language": "^5.4 || ^6.0 || ^7.0", "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6e2ee6755..0764ead64 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -20,6 +20,8 @@ parameters: - '#^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\.$#' - '#^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\.$#' - '#^Method JMS\\Serializer\\GraphNavigator\\DeserializationGraphNavigator\:\:resolveMetadata\(\) should return JMS\\Serializer\\Metadata\\ClassMetadata\|null#' + - '#^ArrayObject<\*NEVER\*, \*NEVER\*> does not accept list\.#' + - '#^ArrayObject<\*NEVER\*, \*NEVER\*> does not accept array\.#' paths: - %currentWorkingDirectory%/src - %currentWorkingDirectory%/tests diff --git a/phpstan/no-typed-prop.neon b/phpstan/no-typed-prop.neon index 105e8d441..26eb7874f 100644 --- a/phpstan/no-typed-prop.neon +++ b/phpstan/no-typed-prop.neon @@ -8,4 +8,3 @@ parameters: - %currentWorkingDirectory%/tests/Fixtures/DocBlockType/Collection/ConstructorPropertyPromotion.php - %currentWorkingDirectory%/tests/Fixtures/DocBlockType/Collection/ConstructorPropertyPromotionWithoutDocblock.php - %currentWorkingDirectory%/tests/Fixtures/DocBlockType/Collection/ConstructorPropertyPromotionWithScalar.php - - %currentWorkingDirectory%/tests/Serializer/BaseSerializationTest.php diff --git a/phpstan/no-unions.neon b/phpstan/no-unions.neon index 26ac059c7..1eafe62b9 100644 --- a/phpstan/no-unions.neon +++ b/phpstan/no-unions.neon @@ -1,3 +1,4 @@ parameters: excludePaths: + - %currentWorkingDirectory%/src/Handler/UnionHandler.php - %currentWorkingDirectory%/tests/Fixtures/TypedProperties/ComplexDiscriminatedUnion.php diff --git a/src/Handler/FormErrorHandler.php b/src/Handler/FormErrorHandler.php index c794e2b2f..7887d9d37 100644 --- a/src/Handler/FormErrorHandler.php +++ b/src/Handler/FormErrorHandler.php @@ -129,7 +129,6 @@ private function getErrorMessage(FormError $error): ?string private function convertFormToArray(SerializationVisitorInterface $visitor, FormInterface $data): \ArrayObject { - /** @var \ArrayObject{errors?:array,children?:array} $form */ $form = new \ArrayObject(); $errors = []; foreach ($data->getErrors() as $error) { diff --git a/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php b/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php index b1ec7ad3c..a618b0441 100644 --- a/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php +++ b/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php @@ -20,6 +20,7 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\PhpDocParser\Parser\TokenIterator; use PHPStan\PhpDocParser\Parser\TypeParser; +use PHPStan\PhpDocParser\ParserConfig; /** * @internal @@ -47,11 +48,25 @@ final class DocBlockTypeResolver public function __construct() { - $constExprParser = new ConstExprParser(); - $typeParser = new TypeParser($constExprParser); + // PHPStan PHPDoc Parser 2 + if (class_exists(ParserConfig::class)) { + $config = new ParserConfig(['lines' => true, 'indexes' => true]); - $this->phpDocParser = new PhpDocParser($typeParser, $constExprParser); - $this->lexer = new Lexer(); + $constExprParser = new ConstExprParser($config); + $typeParser = new TypeParser($config, $constExprParser); + + $this->phpDocParser = new PhpDocParser($config, $typeParser, $constExprParser); + $this->lexer = new Lexer($config); + } else { + // @phpstan-ignore arguments.count + $constExprParser = new ConstExprParser(); + // @phpstan-ignore arguments.count + $typeParser = new TypeParser($constExprParser); + // @phpstan-ignore arguments.count + $this->phpDocParser = new PhpDocParser($typeParser, $constExprParser); + // @phpstan-ignore arguments.count + $this->lexer = new Lexer(); + } } /** From 4b851474693473bfcb426252067a01c94949f84d Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Mon, 25 Nov 2024 09:59:16 +0100 Subject: [PATCH 2/3] Exclude fixtures --- phpstan.neon.dist | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0764ead64..ccb72af0c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -14,14 +14,13 @@ parameters: - '#^Property JMS\\Serializer\\Handler\\FormErrorHandler\:\:\$translator has unknown class Symfony\\Component\\Translation\\TranslatorInterface as its type\.$#' - '#^Cannot call method appendChild\(\) on null\.$#' - '#^Call to an undefined method JMS\\Serializer\\VisitorInterface\:\:setData\(\)\.$#' - - '#^Property JMS\\Serializer\\Tests\\Fixtures\\DocBlockType\\Collection\\CollectionOfNotExistingClasses\:\:\$productIds has unknown class JMS\\Serializer\\Tests\\Fixtures\\DocBlockType\\Collection\\NotExistingClass as its type\.$#' - '#^Call to method expects\(\) on an unknown class Symfony\\Component\\Translation\\TranslatorInterface\.$#' - '#^Call to an undefined method JMS\\Serializer\\VisitorInterface\:\:hasData\(\)\.$#' - - '#^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\.$#' - - '#^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\.$#' - '#^Method JMS\\Serializer\\GraphNavigator\\DeserializationGraphNavigator\:\:resolveMetadata\(\) should return JMS\\Serializer\\Metadata\\ClassMetadata\|null#' - '#^ArrayObject<\*NEVER\*, \*NEVER\*> does not accept list\.#' - '#^ArrayObject<\*NEVER\*, \*NEVER\*> does not accept array\.#' paths: - %currentWorkingDirectory%/src - %currentWorkingDirectory%/tests + excludePaths: + - tests/Fixtures/* From 3d937adb3fd1a1ddceb1383c91f01609fb70d492 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Mon, 25 Nov 2024 10:32:08 +0100 Subject: [PATCH 3/3] Disable reportUnmatchedIgnoredErrors --- phpstan.neon.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ccb72af0c..a9f5f1560 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -24,3 +24,4 @@ parameters: - %currentWorkingDirectory%/tests excludePaths: - tests/Fixtures/* + reportUnmatchedIgnoredErrors: false