Skip to content

Commit

Permalink
BC fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 31, 2022
1 parent 803eb85 commit e588977
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Hooks/TestCaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e588977

Please sign in to comment.