Skip to content

Commit

Permalink
Merge pull request #123 from Nicelocal/master
Browse files Browse the repository at this point in the history
Immutable refactoring
  • Loading branch information
orklah committed Nov 1, 2022
2 parents 5a66a0a + 9044b30 commit e610736
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 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,8 +167,13 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event
}

foreach ($specials['dataProvider'] as $line => $provider) {
$provider_docblock_location = clone $method_storage->location;
$provider_docblock_location->setCommentLine($line);
if (VersionUtils::packageVersionIs('vimeo/psalm', '<', '5.0')) {
$provider_docblock_location = clone $method_storage->location;
$provider_docblock_location->setCommentLine($line);
} else {
/** @var CodeLocation */
$provider_docblock_location = $method_storage->location->setCommentLine($line);
}

if (false !== strpos($provider, '::')) {
[$class_name, $method_id] = explode('::', $provider);
Expand Down Expand Up @@ -328,9 +336,14 @@ static function (
$provider_return_type_string,
$provider_docblock_location
): void {
$param_type = clone $param_type;
if ($is_optional) {
$param_type->possibly_undefined = true;
if (VersionUtils::packageVersionIs('vimeo/psalm', '<', '5.0')) {
$param_type = clone $param_type;
$param_type->possibly_undefined = true;
} else {
/** @var Union */
$param_type = $param_type->setPossiblyUndefined(true);
}
}
if ($codebase->isTypeContainedByType($potential_argument_type, $param_type)) {
// ok
Expand Down

0 comments on commit e610736

Please sign in to comment.