|
8 | 8 | use PhpParser\Node\Stmt\ClassLike; |
9 | 9 | use PhpParser\Node\Stmt\ClassMethod; |
10 | 10 | use Psalm\Codebase; |
| 11 | +use Psalm\CodeLocation; |
11 | 12 | use Psalm\DocComment; |
12 | 13 | use Psalm\Exception\DocblockParseException; |
13 | 14 | use Psalm\IssueBuffer; |
14 | 15 | use Psalm\Issue; |
| 16 | +use Psalm\PhpUnitPlugin\VersionUtils; |
15 | 17 | use Psalm\Plugin\EventHandler\AfterClassLikeAnalysisInterface; |
16 | 18 | use Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface; |
17 | 19 | use Psalm\Plugin\EventHandler\AfterCodebasePopulatedInterface; |
|
21 | 23 | use Psalm\Storage\ClassLikeStorage; |
22 | 24 | use Psalm\Type; |
23 | 25 | use Psalm\Type\Atomic\TNull; |
| 26 | +use Psalm\Type\Union; |
24 | 27 | use RuntimeException; |
25 | 28 |
|
26 | 29 | class TestCaseHandler implements |
@@ -164,7 +167,13 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event |
164 | 167 | } |
165 | 168 |
|
166 | 169 | 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 | + } |
168 | 177 |
|
169 | 178 | if (false !== strpos($provider, '::')) { |
170 | 179 | [$class_name, $method_id] = explode('::', $provider); |
@@ -328,7 +337,13 @@ static function ( |
328 | 337 | $provider_docblock_location |
329 | 338 | ): void { |
330 | 339 | 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 | + } |
332 | 347 | } |
333 | 348 | if ($codebase->isTypeContainedByType($potential_argument_type, $param_type)) { |
334 | 349 | // ok |
|
0 commit comments