Skip to content

Commit e588977

Browse files
committed
BC fixes
1 parent 803eb85 commit e588977

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Hooks/TestCaseHandler.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
use PhpParser\Node\Stmt\ClassLike;
99
use PhpParser\Node\Stmt\ClassMethod;
1010
use Psalm\Codebase;
11+
use Psalm\CodeLocation;
1112
use Psalm\DocComment;
1213
use Psalm\Exception\DocblockParseException;
1314
use Psalm\IssueBuffer;
1415
use Psalm\Issue;
16+
use Psalm\PhpUnitPlugin\VersionUtils;
1517
use Psalm\Plugin\EventHandler\AfterClassLikeAnalysisInterface;
1618
use Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface;
1719
use Psalm\Plugin\EventHandler\AfterCodebasePopulatedInterface;
@@ -21,6 +23,7 @@
2123
use Psalm\Storage\ClassLikeStorage;
2224
use Psalm\Type;
2325
use Psalm\Type\Atomic\TNull;
26+
use Psalm\Type\Union;
2427
use RuntimeException;
2528

2629
class TestCaseHandler implements
@@ -164,7 +167,13 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event
164167
}
165168

166169
foreach ($specials['dataProvider'] as $line => $provider) {
167-
$provider_docblock_location = $method_storage->location->setCommentLine($line);
170+
if (VersionUtils::packageVersionIs('vimeo/psalm', '>=', '5.0')) {
171+
/** @var CodeLocation */
172+
$provider_docblock_location = $method_storage->location->setCommentLine($line);
173+
} else {
174+
$provider_docblock_location = clone $method_storage->location;
175+
$provider_docblock_location->setCommentLine($line);
176+
}
168177

169178
if (false !== strpos($provider, '::')) {
170179
[$class_name, $method_id] = explode('::', $provider);
@@ -328,7 +337,13 @@ static function (
328337
$provider_docblock_location
329338
): void {
330339
if ($is_optional) {
331-
$param_type = $param_type->setPossiblyUndefined(true);
340+
if (method_exists($param_type, 'setPossiblyUndefined')) {
341+
/** @var Union */
342+
$param_type = $param_type->setPossiblyUndefined(true);
343+
} else {
344+
$param_type = clone $param_type;
345+
$param_type->possibly_undefined = true;
346+
}
332347
}
333348
if ($codebase->isTypeContainedByType($potential_argument_type, $param_type)) {
334349
// ok

0 commit comments

Comments
 (0)