From e5889774b0520a0a87365fd75b94707a32a97ae8 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 31 Oct 2022 21:42:45 +0100 Subject: [PATCH] BC fixes --- src/Hooks/TestCaseHandler.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index 1f0f83c..f6b4e5a 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -8,10 +8,12 @@ use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use Psalm\Codebase; +use Psalm\CodeLocation; use Psalm\DocComment; use Psalm\Exception\DocblockParseException; use Psalm\IssueBuffer; use Psalm\Issue; +use Psalm\PhpUnitPlugin\VersionUtils; use Psalm\Plugin\EventHandler\AfterClassLikeAnalysisInterface; use Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface; use Psalm\Plugin\EventHandler\AfterCodebasePopulatedInterface; @@ -21,6 +23,7 @@ use Psalm\Storage\ClassLikeStorage; use Psalm\Type; use Psalm\Type\Atomic\TNull; +use Psalm\Type\Union; use RuntimeException; class TestCaseHandler implements @@ -164,7 +167,13 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event } foreach ($specials['dataProvider'] as $line => $provider) { - $provider_docblock_location = $method_storage->location->setCommentLine($line); + if (VersionUtils::packageVersionIs('vimeo/psalm', '>=', '5.0')) { + /** @var CodeLocation */ + $provider_docblock_location = $method_storage->location->setCommentLine($line); + } else { + $provider_docblock_location = clone $method_storage->location; + $provider_docblock_location->setCommentLine($line); + } if (false !== strpos($provider, '::')) { [$class_name, $method_id] = explode('::', $provider); @@ -328,7 +337,13 @@ static function ( $provider_docblock_location ): void { if ($is_optional) { - $param_type = $param_type->setPossiblyUndefined(true); + if (method_exists($param_type, 'setPossiblyUndefined')) { + /** @var Union */ + $param_type = $param_type->setPossiblyUndefined(true); + } else { + $param_type = clone $param_type; + $param_type->possibly_undefined = true; + } } if ($codebase->isTypeContainedByType($potential_argument_type, $param_type)) { // ok